The purpose of this assignment is to give you practice calling functions, passin
ID: 3756699 • Letter: T
Question
The purpose of this assignment is to give you practice calling functions, passing parameters and return values, saving and storing registers and accessing arrays. This is the code for the data section and the main and swap functions. Be sure to understand what is happening in this code before you continue. data numbers: space 80 #dedare 80 bytes of storage to hold array of 20 integers prompt asciz "How many values to read? space: .asciz .text main: #read data into array lui Sao, 0x1001 #put address of array into parameter Sao jalreadData #call readdata function on $80. Svo, 0 #save number of integers read into Ss0 #print array lui $a0, 0x1001 #put address of array into parameter Sao on Sal, Ss0,0 #put count into parameter jal print #call print function #sort array lui Sad, 0x1001 #put address of array into parameter Sao on Sal , $s0, 0 #put count into parameter jal sort #call sort function #print array lui Sao, 0x1001 #put address of array into parameter Sao on Sal , Ss0,0 #put count into parameter jal print #call print function #exit on Sv0. So, 10 syscall #set command to end program #end program #function swap is called by sort #5a0 holds address of one integer #Sal holds address of another integer swap: 1w St0, 0($a0) lw $11, 0(Sa 1 ) sw Sto, 0(Sal) sw St1, 0(Sa0 ir Sra #get first value #get second value #store first value #store second valueExplanation / Answer
.data
ARR db 50 DUP(?) ;Array of max length 50
.code
readData: ;readData fuction
MOV SI, OFFSET ARR ;transferring arr 0th index in si
PRINT "How many values to read?"
MOV AH,1
INT 21H
AND AL,0FH ;converting from ascii to integer
MOV CL, AL ;storing size of array in cl register
PRINTN
PRINT "Enter elements of array"
PRINTN
JAL INPUT
INPUT: ;Input function to read input from user
INT 21H
MOV ARR[SI],AL ;moving data from al register to arr at si index
INC SI ;increasing si
CMP SI, CL ;comparing counter and size
JL INPUT ;looping if counter is less than size
ret ;return statement (set it according to your need)
print: ;print function
MOV SI, OFFSET ARR ;transferring arr 0th index in si
MOV DX,[SI] ;moving arr value at si index to dx register
MOV AH,2
INT 21H
INC SI ;increasing si
CMP SI, CL ;comparing counter and size
JL print ;looping if counter is less than size
ret ;return statement (set it according to your need)
sort: ;sort function
MOV SI, OFFSET ARR ;transferring arr 0th index in si
MOV DI, OFFSET ARR ;transferring arr 0th index in di
MOV AX,[ARR+SI] ;moving value at 0+si index to ax register
MOV DX,[ARR+DI+1] ;moving value at 0+si+1 index to dx register
CMP AX,DX ;comparing ax and dx register
JG swap ;jump if ax is greater than dx
INC DI ;increasing di
CMP DI,CL ;comparing di and cl
JLE sort ;jump if di less than or equal to cl
INC SI ;increasing si
CMP SI,CL ;comparing si and cl
JLE sort ;jump if si less than or equal to cl
ret ;return statement (set it according to your need)
call readData ;calling readData function
call print ;calling print function
call sort ;calling sort function
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.