Page 1 of 1

Dword or byte?

Posted: Tue Dec 25, 2007 1:52 pm
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?

Posted: Tue Dec 25, 2007 5:03 pm
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.

Posted: Wed Dec 26, 2007 5:37 am
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.)

Posted: Fri Dec 28, 2007 8:01 am
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.

Posted: Fri Dec 28, 2007 5:32 pm
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.