Skip to main content
gamedev.net
🔒 Locked

inline Assembly

Started by CBoardianDavidP Jan 18, 2002 at 4:22 PM 9 replies 350+ views
Original Post
CBoardianDavidP
CBoardianDavidP
I am trying to do some inline Assembly, but am having some problems. I thought you used a variable in Assembly code by using [] around the variable name, but that is not working. Here is my code: int main (void) { char myString[20]; asm { mov dx, [myString] mov ah, a int 21h } getch(); return 0; } It gives me the error: Operand types do not match. When I try to do the mov dx, [myString] part of the code. Anybody know whats wrong and how to fix it? A horse is a horse. There is no excuse for Hungarian notation. DavidP - a CBoardian dragon288@juno.com
A horse is a horse. There is no excuse for Hungarian notation.DavidP - a CBoardiand.pru@juno.com
CBoardianDavidP
CBoardianDavidP
mov dx, myString

does not work. Oh, and with this:

mov ah, a

I meant:

mov ah, 0ah

Which could also be interpreted as:

mov ah, 10

that 10 is base 10 by the way...not 16...

A horse is a horse. There is no excuse for Hungarian notation.

DavidP - a CBoardian
dragon288@juno.com
A horse is a horse. There is no excuse for Hungarian notation.DavidP - a CBoardiand.pru@juno.com
CBoardianDavidP
CBoardianDavidP
okay, the code compiled, but it doesnt work properly. here it is:

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int main (void)
{
char *myString = (char *) malloc(50);

asm {
mov dx, myString
mov ah, 0ah
int 21h
}

cout << myString << endl;

getch();
return 0;
}

It just waits for a key press...then closes...it should be inputing a string...then outputing it...then waiting for a keypress...then closing...

A horse is a horse. There is no excuse for Hungarian notation.

DavidP - a CBoardian
dragon288@juno.com
A horse is a horse. There is no excuse for Hungarian notation.DavidP - a CBoardiand.pru@juno.com
Infinisearch
Infinisearch
I don''t know what compiler u are using or what operating system you are compiling for. But I''ll throw some stuff at u. But before I do I really have to say one thing: BIOS CALLS. Use EDX, unless u are compiling for DOS pointers will be 32bits. U could also try using LEA (load effective address) instead of MOV. Keep in mind FAR and NEAR pointers.

-potential energy is easily made kinetic-
-potential energy is easily made kinetic-
CBoardianDavidP
CBoardianDavidP
maybe one of the problem at runtime is that I am using Windows XP...which doesnt have much DOS support...

how would you do the same thing with BIOS interrupts instead?

A horse is a horse. There is no excuse for Hungarian notation.

DavidP - a CBoardian
dragon288@juno.com
A horse is a horse. There is no excuse for Hungarian notation.DavidP - a CBoardiand.pru@juno.com
Assembler015
Assembler015
its really simple - first, windows would support all the dos int 21h functions through the console (dos emulator basically).

the problem is with your code, try something like this:

    
#include <whatever .h's needed>

char string[20];

int main (void)
{
memset(string, 0, 20);

asm
{
mov dx, segment string
mov ds, dx

lea dx, string
mov ah, 0Ah
int 21h
}
printf("%s", string);
getch();

return 0;
}



that should do it fine if I'm not mistaking, in place of memset you could use that stosb instruction - you choice.

good luck

EDIT: misplaced comma in memset function call

Edited by - Assembler015 on January 19, 2002 11:49:11 AM
CBoardianDavidP
CBoardianDavidP
I am using Borland C++ 5.02.

When I try to compile that code it says "segment" is an undefined symbol.

A horse is a horse. There is no excuse for Hungarian notation.

DavidP - a CBoardian
dragon288@juno.com
A horse is a horse. There is no excuse for Hungarian notation.DavidP - a CBoardiand.pru@juno.com
jenova
jenova
segment => seg

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.