Using EAX in 16-Bit ASM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Metallic-Red

Using EAX in 16-Bit ASM

Post 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...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Using EAX in 16-Bit ASM

Post 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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
fraserjgordon

Re:Using EAX in 16-Bit ASM

Post 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.
AR

Re:Using EAX in 16-Bit ASM

Post 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
aladdin

Re:Using EAX in 16-Bit ASM

Post 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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Using EAX in 16-Bit ASM

Post by bubach »

why not use a 32-bit variable?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Metallic-Red

Re:Using EAX in 16-Bit ASM

Post by Metallic-Red »

Yeah I know that I can easily use a variable, but I was just asking about the use of EAX, etc.
Post Reply