Question: 4) Write code to finish all the functions listed in project1.asm. In project1.asm, an array A of 11 integers are given at the beginning (make
4) Write code to finish all the functions listed in project1.asm. In project1.asm, an array A of 11 integers are given at the beginning (make sure do not change these integers):
43, -5, 11, -12, 64, -7, 14, 71, 103, 13, -27
The finished project1.asm should read in two indices i and j (the range of each index is from 0 to 10) from the console, then load/compute and print out A[i], A[j], A[i]+A[j] and A[i]-A[j]. Here is an example: ----------------------------------------------------- Index i [0~10]: 1 Index j [0~10]: 2
A[i]=-5 A[j]=11 A[i]+A[j]=6 A[i]-A[j]=-16
--------------------------------------------------------------------
I have provided some code in project1.asm. All the needed strings have been defined at the beginning of project1.asm. Please read the comments carefully before you work on this project.
here is the code:
.data baseadd: .word 43, -5, 11, -12, 64, -7, 14, 71, 103, 13, -27
string1: .asciiz "Index i [0~10]: " string2: .asciiz "Index j [0~10]: " string3: .asciiz " A[i]=" string4: .asciiz " A[j]=" string5: .asciiz " A[i]+A[j]=" string6: .asciiz " A[i]-A[j]="
.text main: # Read input i to $s1 addi $v0, $zero, 4 # code for printing string is 4 la $a0, string1 # load address of string to be printed into $a0 syscall # call operating system addi $v0, $zero, 5 # code for reading integer is 5 syscall # call operating system add $s1, $v0, $zero # i in $s1 # Read input j to $s2 addi $v0, $zero, 4 # code for printing string is 4 la $a0, string2 # load address of string to be printed into $a0 syscall # call operating system # Write code here to read input j to $s2 #baseadd of the array to $s5 la $s5, baseadd # Write code here to load A[i] to $s3 # Print A[i] from $s3 addi $v0, $zero, 4 # code for printing string is 4 la $a0, string3 # load address of string to be printed into $a0 syscall # call operating system add $a0, $s3, $zero addi $v0,$zero,1 # prints integer syscall
# Write code here to load and print A[j] # Write code here to compute and print A[i]+A[j]
# Write code here to compute and print A[i]-A[j] # exit addi $v0, $zero, 10 syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
