Write simple MIPS assembly code and simulate it using the simulator that was int
ID: 2291227 • Letter: W
Question
Write simple MIPS assembly code and simulate it using the simulator that was introduced in the lab (QtSpim). 1. Write MIPS assembly code for swapping the contents of two registers, St0 and Stl. (Similar example in the tutorial) 2. Write MIPS assembly code to reverse the bits in a register. Assume the register of interest is St3 . Write MIPS assembly code to print your name in the following format on the screen/console Format: My name is Bond, James Bond. So it should be: My name is "your last name", "your first name last name" 95Explanation / Answer
1.swap values in registers $t0 and $t1:
.text .globl __start
__start:
# swap values $t0 and $t1
sw $t0, x
sw $t1, y
lw $t0, y
lw $t1, x
.data
x:
.word 0x000000FF
y:
.word 0xABCDE080
Q5)program to calculate factorial
code for factorize
.data
newline: .asciiz "
"
.text
.globl main
main:
li $fp, 0x7ffffffc
B1:
# load 0 =>r_N
li $t0, 0
sw $t0,0($fp)
# load 0 =>r_I
li $t0, 0
sw $t0,-4($fp)
# readint =>r_N
li $v0, 5
syscall
add $t0, $v0, $zero
sw $t0, 0($fp)
# load 2=> r0
li $t0, 2
sw $t0,-12($fp)
# i2i
lw $t1,-12($fp)
add $t0,$t1,$zero
sw $t0,-4($fp)
# jump => B2
j B2
B2:
# compare less than or equal to
lw $t1,-12($fp)
lw $t2, 0($fp)
sle $t0, $t1, $t2
sw $t0,-16($fp)
# control branch
lw $t0,-16($fp)
bne $t0, $zero, B3
# jump => B4
j B4
# jump => B3
j B3
B3:
# mod
lw $t1,-4($fp)
lw $t2,-4($fp)
divu $t0, $t1, $t2
mfhi $t0
sw $t0,-20($fp)
# compare equal to
lw $t1,-20($fp)
lw $t2, 0($fp)
beq $t0, $t1, B4
sw $t0-20($fp)
# load 0=> r1
li $t0, 0
sw $t0,-24($fp)
# control branch
lw $t0,-24($fp)
bne $t0, $zero, B4
# jump => B5
j B5
# division
lw $t1,-24 ($fp)
lw $t2,-4 ($fp)
divu $t0, $t1, $t2
mflo $t0
sw $t0,-28($fp)
# i2i
lw $t1,-28($fp)
add $t0,$t1,$zero
sw $t0,0($fp)
# writeint=>r_I
li $v0, 1
lw $t1,-4($fp)
add $a0, $t1, $zero
syscall
li $v0, 4
la $a0, newline
syscall
# jump => B3
j B3
# load 1=> r2
li $t0, 1
sw $t0,-36($fp)
# addition
lw $t1,0($fp)
lw $t2,-36($fp)
addu $t0, $t1, $t2
sw $t0,-40($fp)
# i2i
lw $t1,-40($fp)
add $t0,$t1,$zero
sw $t0,0($fp)
# jump => B3
j B3
B4:
# exit
# exit
li $v0, 10
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.