Defining "variables" in assembly language

12,711

Here's what you see in your "Watches" window:

a = 0 = 0x00 = 0x0000 = 0x00 0000 = 0x0000 0000

b = 167772160 = 16777216 * 10 = 0x1000000 * 0x0A = 0xA000000

c = 655360 = 65536 * 10 = 0x10000 * 0x0A = 0xA0000

d = 10 = 0x0A = 0x0000 000A

What does it mean? It means that your compiler did its job, but your debugger reads c and b as doublewords (4 bytes) instead of bytes.

When it reads in b, it reads its value 0x00, c´s value 0x0000, and d´s value 0x0A on the top, together making it 0xA000000.

Similar thing happens to c. a got lucky, as the next 4 bytes are zero, so the a is really zero.

However, this doesn't always have to be the case. Nothing says that there can't be any garbage after d, not to mention that variables equal to zero may appear in .bss (on a completely different memory location).

Share:
12,711
Oleg Arkhipov
Author by

Oleg Arkhipov

Updated on June 04, 2022

Comments

  • Oleg Arkhipov
    Oleg Arkhipov almost 2 years

    I underdstand that this is extremely stupid quiestion, but I can't figure an answer for some time
    How do I correctly declare and define "variables" in GAS AT&T assembly language?
    For example, I want buffer for 5 bytes, two 1-byte variables (initially with 0 value), 2-byte variable with 0 and 2-byte variable with 10.
    This code doesn't work correctly, at least debugger says (on the first line of the program, after these declarations, just nop instruction) that b and c are big numbers instead of zeros.

    .bss
        .lcomm r, 5
    
    .data
        a:  .byte 0
        b:  .byte 0
        c:  .word 0
        d:  .word 10
    
  • Oleg Arkhipov
    Oleg Arkhipov almost 9 years
    Thanks. But what can I do now? I can't use debugger for adequate watching my variables?
  • user35443
    user35443 almost 9 years
    @Construct I'm not very familiar with kdbg, there may be some settings for it. If you were able to access (possibly underlying) gdb through some interface, or use gdb directly, your problem would be solved. You can still try to compile with as -g, as -g3, or as -ggdb and then load, so there would be some additional debugging information present for kdbg.