Dword or byte?

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
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Dword or byte?

Post by Craze Frog »

After reading a few tutorials and kernel sources I noticed that in the interrupt handlers, some use a byte for the exception number and error code, and some use a dword. Which is correct?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Short answer: Both

Long answer: In most cases the interrupt number is passed on the stack. That means that the number is promoted to 32 bits in any case. The net result is that you can read the argument as both a byte or (signed/unsigned) dword (or word, even) as the significant part does not change. Be aware though that if you write a byte before the call and read a dword inside the function, that there may be garbage in the unmodified 24 bits which alter the resulting number.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Ok, so dword is correct. (It's possible to pass a byte on the stack without promoting it to dword, by the way.)
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

What Combuster means I believe about the stack is that in IA-32, you can't push a byte value onto the stack. The value will be extended to a 32-bit value while being pushed onto the stack. I do not remember if it will be signed or zero extended but it won't be a byte value. The processor will then decrease ESP 4 times as if it has pushed a DWORD onto the stack.
Crazy Frog wrote:It's possible to pass a byte on the stack without promoting it to dword
As far as I know, it is impossible to push a byte value onto the stack in IA-32 using the PUSH instruction but you can move a byte to the stack.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

It's possible to pass a byte on the stack without promoting it to dword
Doing so breaks the cdecl/stdcall/fastcall calling convention, messes up stack alignment, and causes all hell to breaks loose. Not an option, really.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply