Defining "variables" in assembly language

I realize this is a very stupid quiestion, but I can't figure out the answer for some time now
How to properly declare and define "variables" in AT&T GAS assembly language

For example, I want a buffer for 5 bytes, two 1 byte variables (originally with a value of 0), a 2-byte variable with 0 and a 2-byte variable with 10.
This code does not work correctly, at least the debugger says (in the first line of the program after these declarations there is just an instruction nop

) that b

they c

are large numbers instead of zeros.

.bss
    .lcomm r, 5

.data
    a:  .byte 0
    b:  .byte 0
    c:  .word 0
    d:  .word 10

      

+3


source to share


1 answer


This is what you see in the Clock 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? This means that your compiler has done his job, but your debugger reads c

and b

as a double word (4 bytes) instead of bytes.



When it reads in b

, it reads the value 0x00

, c

0x0000

and the d

value 0x0A

from above, doing it together 0xA000000

.

This happens with c

. a

lucky as the next 4 bytes are zero, so it a

really is zero.

However, this is not always the case. Nothing to say that d

there can be no garbage after, not to mention that variables that are equal to zero can appear in .bss

(in a completely different memory location).

+3


source







All Articles