Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 4 – 60-266-manipulate arrays using indexed addressing

OBJECTIVES:
i) To learn how to to write a simple program using loops.
ii) To learn to manipulate arrays using indexed addressing.
iii) To learn to use different data-related operators

Problem: Create and initialize an array of at least 8 unsigned doubleword integers (myArray). Find the number of elements in the array and the size of the array in Bytes. Find the location (offset) of the first array element and store the offset in edx register. Calculate the sum of alternate elements of the array, using indexed addressing. Store the result in an unsigned word integer variable (mySum). You can assume the value of mySum can fit in a 16-bit integer

Hints:

• Use LENGTHOF operator to obtain the length of the array.
• Use OFFSET operator to obtain the address (offset) of the array.
• Update the value of ecx (loop counter) appropriately.
• Use edi as array index.
• Inside loop, add alternate elements.
• Use register window of the debugger to see how register contents are modified after each instruction.

Answer:

INCLUDE Irvine32.inc

.data

	myArray DWORD 11h,22h,333h,44h, 55h, 66h, 77h, 88h, 99h, 0aah
	mySum WORD ?

.code
main PROC
	
	mov ecx, LENGTHOF myArray	; length of array
	mov ebx, SIZEOF myArray	; size of array in number of bytes
	mov edx, OFFSET myARRAY	; logical address of first element stored in edx

	mov ecx,(LENGTHOF myArray+1)/2 	; loop counter
	mov edi,0 					; edi will be used as array index
	mov eax,0 					; clear the accumulator
	L1:
		add eax, myArray[edi] 	; add current array element
		add edi,TYPE myArray * 2 	; point to alternate elements (i.e. skip next element)
		loop L1 				; repeat until ECX = 0

	; store the sum in mySum
	mov mySum, ax 	; Assume sum can fit in 16 bits				
	call DumpRegs
	
exit
main ENDP
END main

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!