Before executing: guess what you think `$t0`-`$t5` will be
Execute it: were you right?
Is this how `and` and `or` behave in Python?
```mips
.text
li $s0, 0
li $s1, 1
li $s2, 2
li $s3, 3
and $t0, $s0, $s1
or $t1, $s0, $s1
andi $t2, $s1, 1
ori $t3, $s1, 0
or $t4, $s1, $s2
and $t5, $s2, $s3
```
Before executing: guess what you think `$t0`-`$t5` will be
Execute it: were you right?
What do `sle` and `sgt` mean? What do they get translated into by the assemler?
```mips
.text
li $s1, 2
li $s2, 2
li $s3, 3
#slt: "set on less than"
slt $t0, $s2, $s3
slt $t1, $s1, $s2
slt $t2, $s3, $s2
slti $t3, $s3, 10
#psuedoinstructions
sle $t4, $s1, $s3
sle $t5, $s1, $s2
sgt $t6, $s3, $s2
```
## Shifting investigation
Execute it: what do `sll` and `srl` do?
What happens if you shift an odd number?
Are these R-Type or I-Type instructions?
```mips
.text
li $s0, 16
#shift left logical
sll $t0, $s0, 1
sll $t1, $s0, 2
#shift right logical
srl $t2, $s0, 2
```
# Conditionals
## Branching
- **Branching** allows MIPS programs to skip around to different parts of the program
- Useful for
- conditional statements (if, if-else, etc.)
- loops
- continue executing at the line labeled `my_label`
```mips
b my_label
#...
my_label:
```
-
continue executing at the line labeled `my_label` if `$s0` and `$s1` are equal
```mips
beq $s0, $s1, my_label
```
-
continue executing at the line labeled `my_label` if `$s0` and `$s1` are _not_ equal
```mips
bne $s0, $s1, my_label
```
## Compiling an `if` Statement
```python
if i == j:
k = 1
print("The value of k is",k)
```
```mips
.data
i: 5
j: 8
k: 0
message: .asciiz "The value of k is "
.text
lw $s0, i
lw $s1, j
bne $s0, $s1, disp_msg
li $s2, 1
sw $s2, k
disp_msg:
li $v0, 4 #4 is the code for printing a string
la $a0, message #the argument for the syscall
syscall
li $v0, 1 #1 is the code for printing an int
lw $a0, k #the argument for the syscall
syscall
```
## Exercise
- Run the above program in Mars, observe the output
- Change it so `i` and `j` are equal, run again
- Translate the following Python program into MIPS
```python
if i == j:
k = 1
else:
k = 2
print("The value of k is",k)
```