0

I have written the following code snippet (working in DOS with masm611) :

.data
msg db 10h,?,10h dup(?)

.code
.startup

lea dx,msg
mov ah,0ah
mov cl,msg
int 21h
mov bl,[msg + 1d]

I am confused as to what the contents of the variable 'msg' is. CL holds the value 10h (assuming i entered 5 characters). But the code [msg+1d] accesses the data stored at the location offset(msg) + 1d. Should it not instead access the location at offset address msg + 1d = 11h ?. Why does it at one place take the contents of the 'msg' but at another the offset of 'msg' ?

The contents of the registers after execution are - enter image description here

As can be seen , CL = 10H and BL=05H.

rohit_r
  • 623
  • 1
  • 6
  • 18
  • 2
    It's unclear what you are saying. `cl` is certainly not `5`, it's the address of `msg` and you shouldn't load that into `cl` as that is only a 8 bit register. `bl` is `5` because `int21/0a` places the number of characters entered into that location. Also writing `1d` is pointless and confusing. `1` is `1` in any base. – Jester Feb 23 '20 at 17:54
  • How is "mov bl,[msg + 1d]" syntactically correct? It should be "mov bl, byte ptr [msg + 1]". – FlatAssembler Feb 23 '20 at 17:55
  • You usually don't need to write the operation size out if it can be deduced from the operands. Not sure if that applies here but since it is supposedly "working in DOS with masm611" I guess it does. – Jester Feb 23 '20 at 18:04
  • 2
    In masm `mov cl,msg` could also possibly mean a memory load, in which case that would be `10h`. At least there would be no problem with operand size then. – Jester Feb 23 '20 at 18:08
  • @Jester I have edited the question to include the contents of the registers using debugx. The contents of CL = 10H and not the address of 'msg'. – rohit_r Feb 24 '20 at 03:16
  • 1
    @physics123 : In MASM (or compatible like JWASM or TASM) `mov cl,msg` and `mov cl,[msg]` are the same thing - they both do `mov cl,[msg]` (which moves the byte at `msg` to CL. The `[]` around a symbol name like this don't matter. `lea dx,msg` could have also been done with a `mov` like `mov dx, offset msg` which moves the 16-bit offset of `msg` to DX. – Michael Petch Feb 24 '20 at 03:31
  • 1
    This answer by @rossridge is a good reference for MASM. `[]` around a **symbol name** are optional. https://stackoverflow.com/a/25130189/3857942 – Michael Petch Feb 24 '20 at 03:35

0 Answers0