Question: a. [ 5 points] Write the MIPS assembly code equivalent to the following HLL code. Assume the variables A, B, and C are in $8,
a. [ 5 points] Write the MIPS assembly code equivalent to the following HLL code.
Assume the variables A, B, and C are in $8, $9 and $10 respectively, and the variable ALLEQUAL is left in $11.
| IF (A == B) AND (B == C) ALLEQUAL = 1; ELSE ALLEQUAL= 0; |
b. [5 points] Complete the following MIPS assembly code (or, you may write your own code), which is an assembly language version of the following java code segment(or, you may write your own code):
If (A[i] != A[i +1])
A[i] = 2 * A [i+1];
At the beginning of this code segment, the only values in registers are the base address of array A
in register $S0 and the value of i is in $S1.
| sll $s1, $s1, 2 add $s0, $s0, $s1 lw $t1, 0($s0) # $t1 A[i] lw $t2, 4($s0) beq $t1, $t2, endIf add $t2, $t2, $t2 sw $t2, 0($s0) endif: |
c.
| .globl main main: addi $s0, $0, -5, # $s0 = x = -5 move $a0, $s0 # to pass the parameter ja l ABS # call abs(x) move $s0, $v0 # x = abs(x) move $a0, $s0 # to print integer x li $v0, 1 syscall li $v0, 10 # to exit the program syscall ABS: bgt $a0, $0, IF # if (x > 0) branch to label IF sub $v0, $0, $a0 # else return -1 * x ( or 0 - x) j ENDIF IF: move $v0, $a0 # return x ENDIF: jr $ra |
[10 points] Complete the MIPS assembly language version of the given java code segment: The program converts a variable to its absolute value and display it on console.
Use $s0 for variable x.
| main(String[] args) { int x = -5; x = abs(x); System.out.println(x); } int abs(int x){ if (x > 0) return x; else return (0 - x); }
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
