Part I
Part I
Effective Address: is the address of the operand which denotes the address
where data is located and it is the resulting address after all calculations.
Opcode Operand
Opcode Reg
Operand
DS
Data Segment
Opcode Reg
Address
EA
Operand
Address +
EA
Ex: MOV ax, [esi+1]
Data-Related Operators
1. OFFSET Operator
2. TYPE Operator
3. LENGTHOF Operator
4. SIZEOF Operator
offset
data segment:
myByte
.data
bVal BYTE ?
wVal WORD ?
dVal DWORD ?
dVal2 DWORD ?
.code
mov esi,OFFSET bVal ; ESI = 00404000
mov esi,OFFSET wVal ; ESI = 00404001
mov esi,OFFSET dVal ; ESI = 00404003
mov esi,OFFSET dVal2 ; ESI = 00404007
.data
var1 BYTE ?
var2 WORD ?
var3 DWORD ?
var4 QWORD ?
.code
3. LENGTHOF Operator: The LENGTHOF operator counts the number of
elements in a single data declaration.
.data LENGTHOF
byte1 BYTE 10,20,30 ;3
array1 WORD 30 DUP(?),0,0 ; 32
array2 WORD 5 DUP(3 DUP(?)) ; 15
array3 DWORD 1,2,3,4 ;4
digitStr BYTE "12345678",0 ;9
.code
mov ecx, LENGTHOF array1 ; 32
.data SIZEOF
byte1 BYTE 10,20,30 ;3
array1 WORD 30 DUP(?),0,0 ; 64
array2 WORD 5 DUP(3 DUP(?)) ; 30
array3 DWORD 1,2,3,4 ; 16
digitStr BYTE "12345678",0 ;9
.code
mov ecx, SIZEOF array1 ; 64
1.
.data
array1 BYTE 10h,20h,30h
.code
mov esi,OFFSET array1
mov al,[esi] ; dereference ESI (AL = 10h)
inc esi
mov al,[esi] ; AL = 30h
.data
array2 word 100h,200h,300h
.code
mov esi,OFFSET array2
mov ax,[esi] ; dereference ESI (AL = 100h)
add esi,2
mov ax,[esi] ; AL = 200h
add esi,2
mov ax,[esi] ; AL = 300h
2.
.data
arrayW WORD 1000h, 2000h, 3000h
.code
mov esi,0
mov ax, arrayW[esi] ; AX = 1000h
3.
.data
arrayb BYTE 10h, 20h, 30h
arrayw WORD 100h,200h,300h
arrayd dword 1000h, 2000h
.code
mov al, arrayb ; AL = 10h
mov al, [arrayb+1] ; AL = 20h
mov al, [arrayb+2] ; AL = 30h
.data
wordList word 1000h,2000h,3000h, 0
.code
mov esi,offset wordList
mov ax, [esi] ; first number
add ax, [esi +2] ; second number
add ax, [esi +4] ; third number
mov [esi +6], ax ; store the sum
Problem 1
Write a program to compute the number of elements in the
following array.
Source byte “Computer Science”, 0
Problem 2
Write a program to sum the elements of array1.
Array1 word 6, 12h, 63, 1001b,’A’