Dword or byte?
-
Craze Frog
- Member

- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Dword or byte?
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?
- Combuster
- 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:
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.
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.
-
Craze Frog
- Member

- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
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.
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.Crazy Frog wrote:It's possible to pass a byte on the stack without promoting it to dword
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.