MIPS Beq Add/Subtract Switch - mips

I am new to MIPS trying to figure out Branches and Switches. All I want to do is set switch 0 to add and switch 1 to subtract. Can someone help and explain what I am doing wrong because every video I watch does not help. Every time I run the program I previously had, all it did was run the add: switch over and over again.
li $a0, 2
li $a1, 1
main:
li $s0, 0xf0100000
li $s1, 0b00000001
li $s2, 0b00000010
start:
lw $t0, 0($s0)
beq <------ This is what I don't understand
nop
add:
addu $v0, $a0, $a1
j start
nop
subtract:
subu $v0, $a0, $a1
j start
nop

Related

MIPS - My loop doesn't perform quite how it should

I am trying to construct a while loop in Mars MIPS assembly however I have run into a bit of a problem, where the loop itself works, however the action of halving the number with each pass of the loop doesn't seem to initiate after the first round.
Below is the loop I have:
div:
sra $s0, $t1, 1 #halves the number in $s0
li $v0, 1
add $a0, $zero, $s0 #Prints out the number in $s0
syscall
li $a0, 32
li $v0, 11 #Prints out a space
syscall
loop:
blt $s0, $s4, exit #Loops to the start of div until it reaches 1
j div
exit:
li $v0, 10 #This is the exit.
syscall
All help is welcome, as I have a terrible feeling a rookie mistake is being made here.

Binary value of a line of code in mips

Hello everyone I am having trouble figuring this out, the question wants me to give the value of the line of code in a binary value of the offset field not too sure what to do please help.
add $t0, $zero, $zero
addi $a0, $zero, 21
loop:
beq $a0, $zero, end
add $t0, $t0, $a0
addi $a0, $a0, -3
j loop
end
For beq $a0, $zero, end give the binary value of the offset field. Briefly explain.

MIPS: is it possible to overwrite certain words of a file?

Is it possible to overwrite a file using MIPS?
I have a file and, under certain conditions (i.e. a user decide to update his personal data or delete completely) I need to delete/overwrite some words or row of the text file I have.
I tried this thing:
I already know how to find which word I would like to replace and, with a store byte i write on a buffer the "new" word.
Then I should save it on file. And that's where my problems begin since, using flag 1 (on syscall 13) overwrites the whole file and flag 9 doesn't apply any change. Here's my code. What am I doing wrong?
loop:
la $t6, empty_space
sb $t6, buffer($s7)
beq $s7, $t5, save_on_file
subi $s7, $s7, 1
j loop
save_on_file:
#open file
li $v0, 13
la $a0, file_out
li $a1, 1
li $a2, 0
syscall
move $s6, $v0
#write on file
li $v0, 15
move $a0, $s6
la $a1, buffer
move $a2, $s7
syscall
#close
li $v0, 16
move $a0, $s6
syscall
j menu

When does stall take place in this code?

Loop: lw $t2, 0($t1)
add $t3, $t2, $s1
sw $t3, 4($t1)
add $t1, $t1, $t9
bne $t1, $t0, Loop
and $s2, $s4, $s5
I have interpreted that stall takes place in second instruction provided that this loop runs 8 times and we are in third iteration. Can stall take place in any more situation?

MIPS Programming in Past Paper

I'm very confused about a question in a university past paper. It is as follows:
What is the value in register $s1 after executing the following piece of MIPS
assembly code?
li $t0, 0x1
li $s0, 0x0
li $s1, 0xa5a5a5a5
loop: and $t1, $t0, $s1
beq $t1, $zero, skip
addi $s0, $s0, 1
skip: sll $t0, $t0, 1 # Shift left logical
bne $t0, $zero, loop
(a) 0x10
(b) 0xa5a5a5a5
(c) 0x0
(d) 0x5a5a5a5a
(e) 0x1
The given answer is A - now, as far as I'm aware, the value of $s1 is not changed after its initial declaration - so how is this the case? I'd have thought it would be B?
This shows the QTSpim:
This shows the PCSpim: