Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The file assign2.asm holds a partial program. The purpose of the program is to r

ID: 2084102 • Letter: T

Question

The file assign2.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 ($a0) 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, class, 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 assign2.asm file into the MARS simulator

Write the code for printstr and make sure that it works correctly.

Write the code for print.

Sample input and output. Note there is no comma after the last number.

Enter a number 1

Enter a number 2

Enter a number 9

Enter a number 11

Enter a number 99

Enter a number 12

Enter a number 24

Enter a number 90

Enter a number 17

Enter a number 82

1, 2, 9, 11, 99, 12, 24, 90, 7, 82

"

NO PSEUDO CODE. Thanks.

Explanation / Answer

Answer:

Code for printstr & print function:

printstr:

      la $a0, prompt // Address Prompt
li $v0, 4 // For the Print String (Service Code)
syscall   
jr $ra // Substitue the value of ra(Return from call)

Hint:

( print:   
    addi $t2, $t2, 10
    jal loop
loop:    beq $t0, $t2, end
    lui $t3, 0x1001
    or $a0, $0, $t3
    ori $v0, $0, 1
    syscall
    addi $t3, $t3, 4
    ori $a0, $a0, 0x0038
    ori $v0, $0, 4 #command to print string at $a0
    syscall
    addi $t0, $t0, 1
    j top )

print:
addi $t2, $t2, 10

   addi $t0, $t0,1 // Enter into the loop by increment 1

   ori $v0, $0, 4 // Print the 1st value and then loop start from the 2nd value

syscall


    jal loop // Jump to loop
loop:    beq $t0, $t2, end   
lui $t3, 0x1001
or $a0, $0, $t3
ori $v0, $0, 1
syscall
addi $t3, $t3, 4

ori $a0, $a0, 0x0038
ori $v0, $0, 4 //Print string at $a0
syscall
addi $t0, $t0, 1
j top

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote