Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: Write a complete program to detect if binary pattern “111” exists in

ID: 670533 • Letter: Q

Question

Question 1: Write a complete program to detect if binary pattern “111” exists in $t0. If yes, $t1 should be 1 and otherwise 0.

For example, if $t0 is 28 in decimal, which is 00011100 in binary in 8 bits (all leading 24 bits are 0 so not shown here), pattern “111” exists; if $t0 is 18 in decimal, which is 00010010 in binary in 8 bits, the pattern does not exist.

.text

.globl main

main: ori $t0, $0, 28

# add your code here

done: li $v0, 10

syscall

--------------------------------------------------------------------------------

Question 2: Write a program to find the difference between the top 2 largest numbers in an array. The starting address of the array is in $s0, and the number of elements in the array is in $s1.

. data

A: .word 90, 2, 93, 66, 8, 120, 121, 11, 33, 9

.text

.globl main

main: la $s0, A

li $s1, 10

# add your code here

done: li $v0, 10

syscall

Explanation / Answer

Question 1:

For solving the question 1 ,we need to first convert the decimal number to binary number and then we have to match the binary pattern "111" in the binary pattern we retrived from the conversion of decimal number to binary.

binary: la $a0, bType #binary function selected, notify user
li $v0, 4 #print notification
syscall
la $a0, in_val #ask user for input decimal number
li $v0, 4 #print
syscall
li $v0, 5 #syscall read int
syscall
move $t0, $v0 #save input value to $t0
li $t1, 2 #load 2 into $t1 to divide by 2
li $v0, 4
la $a0, bRes
syscall #print result tag
binLoop: divu $t0, $t1
mfhi $t2   
mflo $t0   
move $a0, $t2
li $v0, 1
bgtz $t0, binLoop
j main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote