Page 1 of 1
Please help with ASM
Posted: Sun Feb 08, 2004 1:10 pm
by cometkeeper
Hallo, I'm trying to understand some differences between intel and at&t asm.
This intel code works ok. It stores a char into the video memory.
start:
mov ax,0xb800
mov ds,ax
mov si,0x0
mov byte [ds:si],0x22
inc si
mov byte [ds:si],0x07
start1:
jmp start1
I tried to translate it into the at&t asm but I cannot understand where the problem is. Can anyone translate it for me????
OTHER QUESTION if I may:
I'm using djgpp.
I have problem when I try to use asm in my .c file. I have to separate each line with the " otherwise I get an error.
When I use this way and I need to specify some in/out/reg. I get another error: "asm template is not a string constant"
__asm__("movw %0,%%ax" : : "=g" (i) );
this generate that error.... Does anyone know where is the problem?
Thank you and sorry if I kept it long...
Re:PLEASE HELP WITH ASM
Posted: Sun Feb 08, 2004 2:23 pm
by frank
hallo,
Are you dutch/belgium?
I have problem when I try to use asm in my .c file. I have to separate each line with the " otherwise I get an error.
Use the ; to seprate, so like this
Code: Select all
asm volatile("mov $3,%ax";
"mov $4,%bx");
Btw, you can also just use a pointer into the memory
( int * mem ) for writing to the video memory.
I don't know if this is faster in anyway (it might get optimized by the compiler)
Re:PLEASE HELP WITH ASM
Posted: Sun Feb 08, 2004 3:15 pm
by Schol-R-LEA
waits for ears to stop ringing from Cometkeeper's shouting in the Subject line
Hmmn, this probably should be in the General Programming forum... Anyway, here's a quick-and-dirty translation of you code into AT&T syntax. This has not been tested, but it should be what you want:
Code: Select all
start:
movw 0xb800, %ax
movw %ax, %ds
movw 0x00, %si
movb 0x22, %ds:(%si)
incw si
movb 0x07, %ds:(%si)
start1:
jmp start1
Keep in mind that if you are using this for 16-bit real mode programming, you need to add the directive
at the beginning of the code.
For more details on AT&T syntax, see reply #4 in
this thread. HTH. C&CW.
Re:PLEASE HELP WITH ASM
Posted: Sun Feb 08, 2004 3:20 pm
by Therx
Very OT
Schol-R-LEA wrote:
C&CW.
Huh. What's that an abbreviation for?
Pete
Re:PLEASE HELP WITH ASM
Posted: Sun Feb 08, 2004 3:23 pm
by Schol-R-LEA
"Comments and Corrections Welcome". That is to say, if I made a mistake, or if you have something productive to add, feel free to add speak you mind about it. Similarly, "CCW" (without the ampersand) means "Constructive Criticism Welcome".
Re:Please help with ASM
Posted: Sun Feb 08, 2004 4:53 pm
by Pype.Clicker
hmm ... i haven't looked deeply at it, but using "ds <= b800" in a DjGpp environment makes me feel the urge to remind you that DjGPP is a 32 bits compiler, and 32bits mode is unlikely to allow a *selector* that has value b800 (typical from real mode addresses)
Re:Please help with ASM
Posted: Mon Feb 09, 2004 1:56 am
by cometkeeper
Ok, I'll try to explain the problems:
this is may .c
----test.c----
int main(void)
{
int i;
__asm__("movw $0x1, %ax\n
movw $0x2, %bx");
return 0;
}
This generate the error:
test.c:5:17: missing terminating " character
test.c: In function `main':
test.c:6: error: parse error before "movw"
test.c:6:32: missing terminating " character
I compiled with
gcc test.c (maybe I miss some compiler switch???)
To solve this problem I have to do this
__asm__("movw $0x1, %ax\n movw $0x2, %bx");
This doesn't get any error, but when you ave long asm code is
impossible to write every instruction in a row.
Second problem:
__asm__("movw %%ax,%0": : "=g" (i));
generates:
test.c: In function `main':
test.c:5: error: input operand constraint contains `='
I knew that the output operand was the second
__asm__("asm-stat":input:output:register);
Isn't it????
If I separate the row I don't get any error
__asm__("movw $0x1, %ax",
movw $0x2, %bx");
but
__asm__("movw %%ax, %0",
movw %%ax, %%bx"
:
: "=g" (i)
);
gets:
test.c: In function `main':
test.c:9: error: asm template is not a string constant
And... In reply to the translated code I get this error at:
movb $0x22, %ds:(%si)
c:/djgpp/tmp/cchS4U2H.s: Assembler messages:
c:/djgpp/tmp/cchS4U2H.s:12: Error: `%ds:(%si)' is not a valid 32 bit base/index
expression
Thank you....
Re:Please help with ASM
Posted: Mon Feb 09, 2004 3:57 am
by Pype.Clicker
cometkeeper wrote:
Ok, I'll try to explain the problems:
this is may .c
----test.c----
int main(void)
{
int i;
__asm__("movw $0x1, %ax\n
movw $0x2, %bx");
return 0;
}
This generate the error:
test.c:5:17: missing terminating " character
test.c: In function `main':
test.c:6: error: parse error before "movw"
test.c:6:32: missing terminating " character
I compiled with
gcc test.c (maybe I miss some compiler switch???)
Hum. Seems like a little browsing of 'info gcc' may help you
The problem here is that multi-line strings are not really standard in C. Some compilers/version support them, other don't. However, i think ansi-C forces the compiler to concatenate strings separate only by "blank" symbols, thus you could write
and it should work fine ...
Second problem:
__asm__("movw %%ax,%0": : "=g" (i));
generates:
test.c: In function `main':
test.c:5: error: input operand constraint contains `='
I knew that the output operand was the second
__asm__("asm-stat":input:output:register);
Isn't it????
I wouldn't bet on this ... it's more likely to be
asm ("asm-stat":output:input:scratched);
And... In reply to the translated code I get this error at:
movb $0x22, %ds:(%si)
c:/djgpp/tmp/cchS4U2H.s: Assembler messages:
c:/djgpp/tmp/cchS4U2H.s:12: Error: `%ds:(%si)' is not a valid 32 bit base/index expression
you needn't to explicitly require '%ds:' : it's the default segment register... however, (%si) is -- as the assembler tells you -- a 16 bits addressing mode. (%esi) would be more likely to be accepted. I think if you want to use 16 bits addressing with AS, you have to put the A16 prefix override for each instruction, though i never tried it myself ...