Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 ) Using MIPS ( MARS 4 . 5 ) Assembly language. Please comment and screenshot the code. Change the PrintIntArray subprogram so that

Question 1) Using MIPS(MARS 4.5) Assembly language. Please comment and screenshot the code. Change the PrintIntArray subprogram so that it prints the array from the last element to the first element. Please answer the two exercise questions at the end of Ch 9. Just in case I took a screenshot of the code and will copy and paste it.
Heres the code:
.text
.globl main
main:
la $a0, array_base
lw $a1, array_size
jal PrintIntArray
jal Exit
.data
array_size: .word 5
array_base:
.word 12
.word 7
.word 3
.word 5
.word 11
# Subprogram: PrintIntArray# Purpose: print an array of ints# inputs:
$a0- the base address of the array
# $a1- the size of the array
.text
PrintIntArray:
addi $sp, $sp,-16 # Stack record
sw $ra,0($sp)
sw $s0,4($sp)
sw $s1,8($sp)
sw $s2,12($sp)
move $s0, $a0 # save the base of the array to $s0
# initialization for counter loop # $s1 is the ending index of the
loop
# $s2 is the loop counter
move $s1, $a1 move $s2, $zero la $a0 open_bracket #
print open bracket jal PrintString
loop: # check ending condition
sge $t0, $s2, $s1bnez $t0, end_loop
sll $t0, $s2,2 # Multiply the loop counter by 4 to get
# offset
(each element is 4 big)
add $t0, $t0, $s0 # address of next array element
lw $a1,0($t0) # Next array element
la $a0, comma
jal PrintInt # print the integer from array
addi $s2, $s2,1 #increment $s0
b loop
end_loop:
li $v0,4 # print close bracket la $a0,
close_bracket
syscall
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
lw $s2,12($sp) # restore stack and return
addi $sp, $sp,16
jr $ra
.data open_bracket: .asciiz "["
close_bracket: .asciiz "]"
comma: .asciiz ","
.include "utils.asm"
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions