Page 1 of 1
Using EAX in 16-Bit ASM
Posted: Mon Dec 20, 2004 6:15 am
by Metallic-Red
I've made a 16-Bit DOS style OS but in one section of code, I needed to store my data into a 32-Bit value, so I put it in EAX! Will this conflict or anything? The code works but i'm not sure what to expect later on...
Re:Using EAX in 16-Bit ASM
Posted: Mon Dec 20, 2004 6:20 am
by distantvoices
I don't think so. You just need to take care to tell the processor that 32 bit values are to be expected/handled. Maybe you gonna need some prefixes (don't know them by heart. The Faq might contain some hints about that)
*shrugs* Others mileage might be different.
Re:Using EAX in 16-Bit ASM
Posted: Mon Dec 20, 2004 7:59 am
by fraserjgordon
If using the AT&T syntax, specify the command with the "l" suffix, e.g. movl $1, %eax. The assembler will insert an "opsize" command before the opcode (0x67, i think) and this will tell the machine to use the 32-bit register (as long as it is not a 286 or older!)
The "l" suffix isn't strictly needed, but it helps and can make it easier to spot certain errors (e.g. movl $1, %ax).
One last thing - remember that if you use the eax register, you will trash any value stored in ax.
Re:Using EAX in 16-Bit ASM
Posted: Mon Dec 20, 2004 8:37 am
by AR
The prefixes, in Intel/NASM Syntax, are o32, a32, o16 and a16. The "o" prefixes are for the operation, "a" is address size.
http://nasm.sourceforge.net/doc/html/nasmdoc9.html#section-9.3
NASM will automatically prefix the instructions for you though,
dec eax and
dec ax have the same opcode so NASM will prefix it to achieve the desired effect
Re:Using EAX in 16-Bit ASM
Posted: Mon Dec 20, 2004 4:45 pm
by aladdin
since the processor knows all its regs (in 16bit and 32bit modes) using EAX will not make any conflit, the only problem you can get, can happens with old CPUs
Re:Using EAX in 16-Bit ASM
Posted: Tue Dec 21, 2004 11:55 am
by bubach
why not use a 32-bit variable?
Re:Using EAX in 16-Bit ASM
Posted: Thu Dec 23, 2004 6:35 am
by Metallic-Red
Yeah I know that I can easily use a variable, but I was just asking about the use of EAX, etc.