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

As you can see in this example, a part of the code is labeled as loop. The b ins

ID: 3890874 • Letter: A

Question

As you can see in this example, a part of the code is labeled as loop. The b instruction in code does a branch to where the loop label is placed. But every loop needs a condition to s By using the branch if equal (beq) instruction the program is checking if the condition S equal to St0 is satisfied or not. If the condition is satisfied it branches to the label specified in instruction (the end loop label in this case), otherwise another iteration of the loop is execut Exercise: Try to interpret the above code for yourself and guess how m we swap the instructions in lines 12 and 13, does it affect the number of iterations or not? Exp the reasons. Assignments Assignment 1 Write a program that reads two signed integers base 10. The program must print the number which is smaller. Comment your code appropriately. Assignment 2

Explanation / Answer

.text
.align 2
.globl main

main:
# this program prints out the minimum of two numbers enterd

li $v0, 4
la $a0, read1
syscall
li $v0, 5 # read keyboard into $v0
syscall
move $t0,$v0 # storing first number in $t0

li $v0, 4
la $a0, read2
syscall

li $v0, 5 # read keyboard into $v0
syscall
move $t1,$v0 # storing second number in $t1

bge $t1, $t0, L1
move $t0, $t1 # minimum number in $t0

L1:
li $v0, 4 # printing result
la $a0, result
syscall

li $v0, 1 # print integer function call 1
move $a0, $t0 # integer to printing minimum number
syscall

end: jr $ra

.data
read1: .asciiz "Enter the first number "
read2: .asciiz "Enter the second number "
result: .asciiz "The Minimum number is "

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