05.08.2014 Views

Quiz -Memory Addressing

Quiz -Memory Addressing

Quiz -Memory Addressing

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

addrmods<br />

@ P. Klimo<br />

October 2005<br />

Base Relative:<br />

Operand offset given by a sum of a value held in either<br />

BX or BP registers and a constant offset specified as an<br />

operand.<br />

A typical application would be to access various structures containing a variable size<br />

elements, using the register value as the pointer to the start of the structure and the<br />

displacement to pint at the start of the element within the structure.<br />

Example:<br />

; Constant definitions<br />

name EQU 0<br />

height EQU 20<br />

age EQU 30<br />

; Structure Definition with initial data<br />

my_details 20 DB "Paul Klimo" ; name (element)<br />

10 DB "2.3 m " ; height (element)<br />

5 DB '2', '1' ; age (element)<br />

; Data for other structures (may be not initialized)<br />

his_details 35 DB ??<br />

her_details 35 DB ??<br />

; This code retrieves the age of the person as a string of 2 ASCII letters held in AX<br />

MOV BX, my_details<br />

CALL get_age<br />

;point to base of structure<br />

;call subroutine that<br />

;returns with ASCII age<br />

;string in AX<br />

..... ; do something with it<br />

ADD BX, 35<br />

CALL get_age<br />

...<br />

; next customer, please<br />

; Subroutine (procedure) get_age<br />

; Get two bytes at offset age into the start of array pointed by BX<br />

get_age MOV AL, [BX + age+1] ; AL has low ASCII of age<br />

MOV AH, [BX + age] ; AH has high ASCII of age<br />

RET<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!