Hi Can someone help me write the the code for this assignmen
Hi. Can someone help me write the the code for this assignment. There are 4 functions in the program, but only two of them need to be completed. I will list the instructions and then the .asm file that is used.
Instructions:
.asm file:
Assignment 2 The file ass asm holds a partial program. The purpose of the program is to read in a list of 10 integers and then print them out. There are 4 functions in the program, 2 of which you are to complete Main: This function will call getdata and print. Main is complete and should not be changed. Getdata: This function reads 10 integers and stores them into memory. There is one parameter ($a0) which holds the address of where the list of numbers is to be stored. Getdata calls the function printstr to print the prompt. Getdata is complete and should not be changed. Printstr: This function is to print a string. There is one parameter (Sa0 which holds the address of the string to print. You are to complete this function so it performs as required. This function is call from the getdata function and the print function. Print: This function is to print the list of integers. The integers must all be on the same line of output and be separated by a comma and space (already in the data segment). See the example input and output below. This function must call the printstr function to print the comma string. Remember that as this function calls another, it must save and restore the $ra. Specifics Use only the instructions covered to date. Do not use pseudo-instructions. See the information under MARS for preventing the use of pseudo-instructions Make sure that your print function calls the printstr function correctly and that the stack is used correctly. Documentation: Comment the beginning of your programs with your name, plass, and assignment number. Comment every instruction. Assignment submittal: Upload your assembly language program (asm file) using this link on Blackboard Hints on getting started: Load the assi asm file into the MARS simulator Write the code for printstr and make sure that it works correctly. Write the code for printSolution
in this question we have to fill the commented part of the code with its corresponding assembly language instruction, and also provide comments for every instruction .
bold will be the answers.
---------------
.data
.space 40 # set aside 40 bytes for 10 integers
prompt: .asciiz \"Enter a number \" # address 0x10010028
comma: .asciiz \", \" # address 0x10010038
.globl main
.text
main:
lui $a0, 0x1001 # get start of data segment
jal getdata # call getdata function
lui $a0, 0x1001 # get start of data segment
jal print # call print function
ori $v0, $0, 10 # set command to exit
syscall # end program
# printstr
# paramters: $a0 holds address of string to print
# purpose: print the string parameter
printstr:
#mips function to print a string with a0 containing its address
#v0 = 4 will take the base address and print the string
li $v0, 4
syscall #will print the string
jr $ra
getdata:
addi $sp, $sp, -4 # allocate space on stack
sw $ra, 0($sp) # save $ra
ori $t1, $a0, 0 # address of array
lui $t1, 0x1001 #start of data
ori $a0, $a0, 0x0028 # address of prompt
ori $t0, $0, 10 # counter
top: beq $t0, $0, ret # while not 0
jal printstr # call function to print prompt
ori $v0, $0, 5 # set command to read integer
syscall # read int
sw $v0, 0($t1) # save int in memory
addi $t1, $t1, 4 # increment to next location
addi $t0, $t0, -1 # decrement counter
j top # repeat
ret: lw $ra, 0($sp) # restore return address
addi $sp, $sp, 4 # clean up stack
jr $ra # return from call
# parameter: $a0 holds address of list in memory
# purpose: print the list separated by commas
#we will make v0 as 1 , so it will print the value at a0, then increase the address of a0 to get next value , #and so one till we print 10 required value
#since a0 is preserved to be passed we do not need to pass it as a parameter and we can directly use it
print:
li $t0, 0 #initializing t0 to 0 to keep count
move $t1, $a0 #moving address of a0 to t1 so we do not loose it
li $t2,10 #initializing it to 10
jr $ra
------------------------------------
thank you


