Reputation: 55
So, I have such structure:
String STRUC
max_length db 254
real_length db ?
buffer db 255 dup(?)
String ENDS
In data segment I define variable of my «String» type:
source_str String <>
And in code segment I'm trying to get the offset of structure member «buffer»:
mov bx, offset source_str ; in BX we have the offset of structure
lea dx, [bx].buffer ; OK, the right offset in DX
mov ax, offset [source_str].buffer ; this works fine too
mov dx, offset [bx].buffer ; but this gets _wrong_ offset, according to td
I'm beginner and this is the way I think: we have an offset (in register or as label) - address, place it between [] and get the value - it's like pointer dereferencing in C/C++.
And my question is: why the last command doesn't work as I think it should? Is there a way to do this using "mov" and offset in BX register?
Upvotes: 1
Views: 900
Reputation: 28921
For masm 6.11 the struc name needs to be included:
lea dx, (String ptr [bx]).buffer
For the other problem, you can't use offset with a base register:
mov dx, offset (String ptr [bx]).buffer ; invalid
You could use add, but lea does the same thing with one instruction:
mov dx, bx
add dx, offset (String ptr ds:0).buffer
Upvotes: 3