Implement a subroutine by using the program in assignment one so that it becomes
ID: 3788945 • Letter: I
Question
Implement a subroutine by using the program in assignment one so that it becomes a subroutine. The sub- routine, LARGE, has to find the largest number in a list. The main program passes the number of entries and the address of the start of the list as parameters to the subroutine via registers r4 and r5. The subroutine returns the value of the largest number to the calling program via register r2. A suitable main program is given for use. Program that finds the largest number in a list of integers k/ text global start Start: movia r8, RESULT r8 points to the result location r4 holds number of elements in the list ldw r4, 4(r8) addi r5, r8, 8 r5 points to the start of the list call LARGE r2 holds the subroutine return value stw r2, (r8) STOP: br STOP LARGE: RESULT skip word NUMBERS word 4, 5, 3, 6 .word 1, 8, 2Explanation / Answer
DATA SEGMENT
ARR DB 1,4,2,3,8,6,7,5
LEN DW $-ARR
LARGE DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
MOV LARGE,AL
MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE
MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
CODE ENDS
END START
Output before execution :
ARR 1,4,2,3,8,6,7,5
LEN 8
LARGE 0
Output after execution :
ARR 1,4,2,3,8,6,7,5
LEN 8
LARGE 8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.