1. Using branch and jump instructions implement the following code blocks in MIP
ID: 3543292 • Letter: 1
Question
1. Using branch and jump instructions implement the following code blocks in MIPS assembly language:
Assuming array A is stored in memory starting at the memory address that is the content of register $s0.
int A[100];
a)
for (i = 0, i < 100, i++)
{
A[i] = 0;
};
______________________________________
b)
i = 0;
while (++i < 100) A[i] = 0;
_______________________________________
c)
i = 0;
do {
A[i] = 0;
i = i + 1;
while i < 100;
}
2. Write a MIPS assembly language program that prompts for a positive number and return the sum of all positive numbers that is smaller or equal to the input number. Remember to comment your program clearly.
Explanation / Answer
please rate - thanks
This is multiple questions-against chegg policy, but I'm in a good mood
this is a and c
.text
.globl main
main:
move $t2,$0 #t2 initialize it to 0
move $t1,$0 #i=0
la $t3,A
li $t0,100
loop: sw $t2,0($t3)
addi $t3,$t3,4
addi $t1,$t1,1
blt $t1,$t0,loop
.data
A: .space 400
---------------------------------------
b--
.text
.globl main
main:
move $t2,$0 #t2 initialize it to 0
move $t1,$0 #i=0
la $t3,A
li $t0,100
loop: addi $t1,$t1,1
addi $t3,$t3,4
beq $t1,$t0,done
sw $t2,0($t3)
j loop
done:
.data
A: .space 400
.text
.globl main
main:
la $a0, m1 # Display a message.
li $v0, 4
syscall
li $v0, 5
syscall
move $t2,$0 #t2 will be sum-initialize it to 0
move $t1, $v0 #i=max
loop: add $t2,$t2,$t1 #sum+=i
addi $t1,$t1,-1 #i--
bgtz, $t1,loop #i>0 yes loop
end:
la $a0, m6 # print a newline.
li $v0 4
syscall
move $a0, $t2
li $v0 1 #print sum
syscall
la $a0, m8 #Prints Goodbye.
li $v0 4
syscall
la $v0,10
syscall # au revoir...
.data
m1: .asciiz "Enter a Number : "
m5: .asciiz " "
m6: .asciiz "The sum is: "
.align 2
m8: .asciiz " Program Exited "
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.