Reputation: 794
I have the following code, in x86 assembly, which tries to print X on the screen:
mov ah , 0x0e
mov al , the_secret
int 0x10
mov al , [the_secret]
int 0x10
mov bx , the_secret
add bx , 0x7c00
mov al , [bx]
int 0x10
mov al , [0x7c1e]
int 0x10
jmp $ ; Jump forever.
the_secret :
db " X "
times 510-($-$$) db 0
dw 0xaa55
When I check the above code in GDB I found that jmp $ command is stored in address 0x7c1b. But GDB shows different data sizes at different addresses. For example:
(gdb) p/x *0x7c1e
$5 = 0x2058
(gdb) p/x *0x7c1b
$6 = 0x5820feeb
(gdb) p/x *0x7c1d
$7 = 0x205820
Sometimes it gives 2 bytes sometimes 4 bytes or 3bytes. Shouldn't it print 2bytes always, which is the word size in x86 (since I am in real mode). Why is it showing different sizes of data at these addresses?
I am also showing the hex dump created after assembling the above assembly code:
7c00: b4 0e b0 1d cd 10 a0 1d 00 cd 10 bb 1d 00 81 c3
7c10: 00 7c 8a 07 cd 10 a0 1e 7c cd 10 eb fe 20 58 20
7c20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Upvotes: 0
Views: 511
Reputation: 881443
It's actually getting four bytes every time, it's just that, if the upper bytes are zero, it doesn't show them in the output, for the same reason that you wouldn't write seven as 00000007
.
For example, in printing out the two-byte value of 6410, you would see 0x40
. If the two-byte vale was 1234510, you'd see 0x3039
.
From your hex dump, you can see this sequence:
7c1b: eb fe 20 58 20 00 00
So, at the given addresses, you see the bytes (and value with high zero bytes not printed):
7c1b: eb fe 20 58 (5820feeb)
7c1d: 20 58 20 00 ( 205820)
7c1e: 58 20 00 00 ( 2058)
Upvotes: 2