I am confused as to how memory is stored when declaring variables in assembly language. I have this block of sample code:
val1 db 1,2
val2 dw 1,2
val3 db '12'
From my study guide, it says that the total number of bytes required in memory to store the data declared by these three data definitions is 8 bytes (in decimal). How do I go about calculating this?
It also says that the offset into the data segment of val3 is 6 bytes and the hex byte at offset 5 is 00. I’m lost as to how to calculate these bytes and offsets.
Also, reading val1 into memory will produce 0102 but reading val3 into memory produces 3132. Are apostrophes represented by the 3 or where does it come from? How would val2 be read into memory?
You have two bytes,
0x01and0x02. That’s two bytes so far.Then you have two words,
0x0001and0x0002. That’s another four bytes, making six to date.The you have two more bytes making up the characters of the string ’12’, which are
0x31and0x32in ASCII (a). That’s another two bytes bringing the grand total to eight.In little-endian format (which is what you’re looking at here based on the memory values your question states), they’re stored as:
(a) The character set you’re using in this case is the ASCII one (you can follow that link for a table describing all the characters in that set).
The byte values
0x30thru0x39are the digits0thru9, just as the bytes0x41thru0x5Arepresent the upper-case alpha characters. The pseudo-op:is saying to insert the bytes for the characters
'1'and'2'.Similarly:
would give you the hex-dump representation: