do number 5 Using the MARS or SPIM simulator develop a program that will evaluat
ID: 3795116 • Letter: D
Question
do number 5
Using the MARS or SPIM simulator develop a program that will evaluate the following expression: 3*n + n * (n - 1) - 15 where n is stored in a data location and is set to 15. Your program should use the system calls to print the result and to exit the program. Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If (n is even) {n = n/2; else n = 3 * n + 1 In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the program. Section 3: You are to take the conditional from the previous section and build a loop around it to find the Collatz sequence. The structure of tins would be: while(n > 1) {If(n is even) {n = n/2;} else {n = 3*n + 1:} CoutExplanation / Answer
REFER THIS STANDARD REGISTERS AND CONVENTIONAL NAME
$LFB0 = .
gcd_algorithm(int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
lw $2,36($fp)
bne $2,$0,$L2
nop
lw $2,32($fp)
b $L3
nop
lw $3,32($fp)
lw $2,36($fp)
slt $2,$3,$2
bne $2,$0,$L4
nop
lw $2,36($fp)
blez $2,$L4
nop
lw $3,32($fp)
lw $2,36($fp)
teq $2,$0,7
div $0,$3,$2
mfhi $2
move $5,$2
lw $4,36($fp)
jal gcd_algorithm(int, int)
nop
b $L3
nop
b $L1
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
$LFB1 = .
main:
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
move $fp,$sp
lui $28,%hi(__gnu_local_gp)
addiu $28,$28,%lo(__gnu_local_gp)
lw $2,%got(__stack_chk_guard)($28)
lw $2,0($2)
sw $2,36($fp)
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
lw $2,%call16(printf)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
addiu $3,$fp,28
addiu $2,$fp,24
move $6,$3
move $5,$2
lui $2,%hi($LC1)
addiu $4,$2,%lo($LC1)
lw $2,%call16(scanf)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
lw $2,24($fp)
lw $3,28($fp)
move $5,$3
move $4,$2
jal gcd_algorithm(int, int)
nop
lw $28,16($fp)
sw $2,32($fp)
lw $2,32($fp)
beq $2,$0,$L6
nop
lw $2,24($fp)
lw $3,28($fp)
lw $7,32($fp)
move $6,$3
move $5,$2
lui $2,%hi($LC2)
addiu $4,$2,%lo($LC2)
lw $2,%call16(printf)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
b $L7
nop
lui $2,%hi($LC3)
addiu $4,$2,%lo($LC3)
lw $2,%call16(puts)($28)
move $25,$2
1: jalr $25
nop
lw $28,16($fp)
move $2,$0
lw $3,%got(__stack_chk_guard)($28)
lw $4,36($fp)
lw $3,0($3)
beq $4,$3,$L9
nop
lw $2,%call16(__stack_chk_fail)($28)
move $25,$2
1: jalr $25
nop
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
j $31
nop
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.