Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Translate the following code into MIPS assembly. It needs to follow the MIPS calling convention (the address of the array should be passed in using
Translate the following code into MIPS assembly. It needs to follow the MIPS calling convention (the address of the array should be passed in using register $a0, the value of n in register $a1, and the value of v in register $a2.
I'm adding a test program for you to be able to test the MIPS code. Here it is:
# $s7 - save $ra # $s2 - current address of the string to be tested # $s3 - used as a temporary register # $a0 - for function parameter / syscall parameter # $v0 - syscall number / function return value .text .globl main main: addu $s7, $ra, $zero, # Save the ra la $a0, int_prompt li $v0, 4 syscall li $v0, 5 syscall add $a2, $v0, $zero #save the value to a2 add $s6, $a2, $zero la $a0, array_a # the address of the array li $a1, 1000 # the size of the array of 1000 jal set addi $s2, $zero, -1 bne $s2, $v0, no_good la $s2, array_a lw $a0, 0($s2) # $a0 is the integer to be printed li $v0, 1 # system call to print an integer syscall # print int la $a0, space_msg li $v0, 4 syscall lw $a0, 4000($s2) # $a0 is the integer to be printed li $v0, 1 # system call to print an integer syscall # print int add $s1, $zero, $zero for_loop: slti $s0, $s1, 1000 beq $s0, $zero, end_loop sll $s4, $s1, 2 addu $s3, $s2, $s4 #a[s1] lw $s4, 0($s3) bne $s6, $s4, no_good addi $s1, $s1, 1 j for_loop end_loop: li $v0, 4 #it is working la $a0, is_good_msg syscall j end_main no_good: #it is not working li $v0, 4 la $a0, not_good_msg syscall end_main: addu $ra, $zero, $s7 #restore $ra since the function calles #another function jr $ra add $zero, $zero, $zero add $zero, $zero, $zero ########## End of main function ######### .data #Data segment starts here is_good_msg: .asciiz " The program is working properly. " not_good_msg: .asciiz " The program is not working properly. " int_prompt: .asciiz "Please enter an integer: " space_msg: .asciiz " " array_a: .align 2 .space 4000 .word -5, -4, -3, -2, -1
Thanks!
int set (int a[], int n, int v) int for i a[1] return i; (i-n-1; i = 0: i-) { = v; int set (int a[], int n, int v) int for i a[1] return i; (i-n-1; i = 0: i-) { = vStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started