raphnguyen
raphnguyen

Reputation: 3605

Assembly Language Byte counting

I am a bit confused with how variables are stored in the data segment. We are given this segment of code:

      .data
vala  dw  1234h
valb  db  1,2,3,4
valc  db  '1234$'
vald  db  '12'

I made an offset data table like so:

offset  00  01  02  03  04  05  06  07  08  09  10  11
data    34  12  01  02  03  04  31  32  33  34  31  32

I don't think I am loading it into memory correctly because the total number of bytes required in memory is 13 and I only have 11 here. Can someone comment on where I went wrong?

There is another question that asks how many bytes are written to the standard output device after these instructions:

mov  dx,offset valb    ;valb has 4 bytes
mov  ah,9              ;4 bytes is written to the output
int  21h               ;for a total of 8 bytes

Am I thinking through this segment of code the right way?

Upvotes: 0

Views: 1517

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62106

You listed 12, not 11. Just count them. There's one byte missing for the dollar character. Other than that the offsets seem fine.

Also, function 9 only prints text, not binary numbers. It won't print the 4 bytes (1, 2, 3 and 4) from valb in a human-readable way. How many bytes exactly it'll print... well, it won't print the dollar because it's used as the string terminator (see the documentation, btw, it's all there). So, it should be just 8 (4 weird characters for bytes 1 through 4 and characters "1", "2", "3" and "4").

Upvotes: 1

Related Questions