I am working through some indirect addressing problems and I am not sure how to properly count bytes. We are given this code:
.data
v1 db 9,7,5,3,1
v2 dw 0
v3 dw -1
v4 db '$'
mov dx,offset v2
mov ah,9
int 21h
The question asks how many bytes will have been written to the standard output device after these instructions have been executed and the answer is 4.
For this problem, I set it up like so:
offset 0 1 2 3 4 5 6 7 8 9
data 09 07 05 03 01 00 00 FF FF 24
We are moving 5 into dx, writing two bytes 00 05. We then set the dos code to write it out, so our output writes out the two bytes making four? Please correct me if my logic is wrong.
DOS function 9 writes starting at the offset in DX until it reaches a
$
. You've loaded the offset of V2 into DX. You've defined V2 and V3 as two bytes apiece (none of which will contain a "$"), and those are followed by V4 (containing the$
). Therefore, it writes the four bytes of V2 and V3, then stops.Edit: I should add that contrary to the title question, none of the code you've shown actually does any indirect addressing (though DOS function 9 undoubtedly does use indirect addressing, reading from the address loaded into
dx
).