{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

proc-exercise_soln

# proc-exercise_soln - Pass addresses of array size and sum...

This preview shows pages 1–2. Sign up to view the full content.

Exercise 1 — addresses via registers Write a procedure to add all elements in an array. Pass addresses of array, size, and sum through registers. Show the calling program. Let VECTOR be the array, VSIZE hold the size, and VSUM hold the sum. All these variables are word variables. Let BX hold the address of VECTOR, CX hold the value of VSIZE, and DI hold the address of VSUM. ADDARRAY PROC FAR PUSH AX PUSH BX PUSH CX MOV AX, 0 NEXT: ADD AX, [BX] ADD BX, 2 LOOP NEXT MOV [DI], AX POP CX POP BX POP AX RET ADDARRAY ENDP Calling program LEA BX, VECTOR MOV CX, VSIZE LEA DI, VSUM CALL ADDARRAY

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Exercise 2 — addresses via table Write a procedure to add all elements in an array.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Pass addresses of array, size, and sum through a table in memory. Show the calling program. Let VECTOR be the array, VSIZE hold the size, and VSUM hold the sum. All these variables are word variables. Let TABLE hold the address of VECTOR, TABLE+2 hold the address of VSIZE, and TABLE+4 hold the address of VSUM. ADDARRAY PROC FAR PUSH AX PUSH BX PUSH CX PUSH DI MOV BX, TABLE MOV DI, TABLE+2 MOV CX, [DI] MOV DI, TABLE+4 MOV AX, 0 NEXT: ADD AX, [BX] ADD BX, 2 LOOP NEXT MOV [DI], AX POP DI POP CX POP BX POP AX RET ADDARRAY ENDP Calling program LEA BX, VECTOR MOV TABLE, BX LEA BX, VSIZE MOV TABLE+2, BX LEA BX, VSUM MOV TABLE+4, BX CALL ADDARRAY...
View Full Document

{[ snackBarMessage ]}