pan069
Member
- Joined
- Jun 4, 2019
- Messages
- 49
Imagine I have a STRUCT that looks like this:
And that I have a pointer to such a STRUCT in memory:
I.e. the high word of student_ptr is the segment, the lower word of student_ptr is the offset (usually zero if we use DOS 21h function 48h to allocate memory for it).
If I want to load the value the age attribute into a register, then I can simply do:
The mov instruction will compile to:
Which is correct. The age attribute "within" the STUDENT struct is at offset 1 (relative to the address/pointer).
However, now I want to compare the name of the student to something else and do a "repe cmpsb" on it against with what ever is loaded into es:di. So, I want to load ds:si with the address of the name attribute. However, if I do this:
Then si will not be loaded with 2 but ds:si will be set to the value of the "offset" of student_ptr + 2. E.g. if student_ptr is located in cs at offset 50, ds:si wil be set to the dd located at cs:52.
What is the correct syntax that I can use to load ds:si with the correct address to the name attribute, i.e. ds being the segment stored in student_prt and si set to the offset stored in student_ptr + 2?
Code:
STUDENT struct
status db ?
age db ?
name 20 dup(?)
STUDENT ends
Code:
student_ptr dd STUDENT
If I want to load the value the age attribute into a register, then I can simply do:
Code:
lds si,student_ptr
mov al,ds:[si].age
Code:
mov al,[si+1]
However, now I want to compare the name of the student to something else and do a "repe cmpsb" on it against with what ever is loaded into es:di. So, I want to load ds:si with the address of the name attribute. However, if I do this:
Code:
lds si,student_ptr.name
What is the correct syntax that I can use to load ds:si with the correct address to the name attribute, i.e. ds being the segment stored in student_prt and si set to the offset stored in student_ptr + 2?
Last edited: