Write MIPS code that sets bits 7 and 9 (makes them 1) in $t0. The code should pr
ID: 3762433 • Letter: W
Question
Write MIPS code that sets bits 7 and 9 (makes them 1) in $t0. The code should preserve the contents of all other bits. (HINT: Use an “ori” operation) (Note: Only 1 line is necessary)
Write MIPS code that clears bits 11 and 13 (makes them 0) in $t0. The code should preserve the contents of all other bits. . (HINT: Use an “andi” operation) (Note: Only 1 line is necessary)
Write MIPS code that prints "It is negative" when the value in register $t1 is less than 0.
.data
negative: .asciiz "It is negative"
.text
li $t1, -30 ##<--Note $t1 is set to a negative
### your code goes here ###
Explanation / Answer
Question:1
## ori makes an OR operation on 2nd and 3rd arguments and store the result in 1st argument
## 3rd argument should be immediate data from ori
## OR operation with 1 sets the bit
ori $t0, $t0, 101000000 ## 7th and 9th bits from right are set to 1.
Question 2:
## andi makes an AND operation on 2nd and 3rd arguments and store the result in 1st argument
## 3rd argument should be immediate data from andi
## AND opearation with 0 clears the bit
ori $t0, $t0, 0101111111111 ## 11th and 13th bits from right are set to 0.
Question 3:
.data
negative: .asciiz "It is negative"
.text
li $t1, -30 ##<--Note $t1 is set to a negative
### your code goes here ###
bltz $t1, offset # Branch on less than zero. if value in $t1 is less than zero then branches to offset
li $v0, 10 # system call code for exit is 10
syscall # call operating sys
offset:
li $v0, 4 # system call code for printing string is 4
la $a0, negative # load address of string to be printed into $a0
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.