MORE OPERATIONS

Hi and lo are two special registers to avoid overflowing mult If we multiply two registers we get at most 64 bits so if it overflows the higher bits goes into the Hi register and the lower bits goes to the lo. If it doesn’t overflow, it will only be in lo. 32 bits

div 
does quotient and remainder
puts quotient(/) into lo and remainder (%)into hi

Access data from registers hi and lo. (copying) - mfhi d

RAM Large amount of memory stored outside of the CPU. Slower to access. Instructions are in RAM with address 0 and increase by word size. Memory in RAM: think of a an array of bytes. Word has index of multiple of 4 because a word is 4 byts. Words are aligned typically in the multiples of 4.

Do computing in the registers but we need more instructions to move the data from the RAM to the registers.

OPERATIONS ON RAM

address is $s and the value is $t
lw load from ram $t 
sw store in ram? $t is the source
is is the off set (a value)
sum of i and $s needs to be aligned

EX:

lis $8
.word 0x7
lis $9
.word 4
mult $2, $9
mflo $3
add $3, $3, $1
sw $8, -4($3)
jr $31
notes: document the process

bytes x words in bytes $3 length in bytes

BRANCHING beq $s, $t, i pc = program counter `if the values in two registers are equal then skip i many instructions.

bne $s, $t, i

EX: Wrtie an assembly language MIPSprgram that places the value 3 in register 1 is odd and places the value 11 in register 8 .word 2 : if remainder is 0 then it is even, value itself is in register 1 lis 2 .word 11 div 8 mfhi 3, 2, 0: if it’s odd we don’t skip and take value in 9 an places it in register 2 jr $31

INEQUALITY COMMAND slt s, d to be 1, other wise sets is it to be 0. - Notes: needs to know if it’s signed or unsigned. Only works if both are the same.

EX: Negates the value in register 2, 0: if 1<0, sets register 2 to 1. 2, 1, 1: substract dollar 1 from 0, that takes the complement? jr $31 Idea: Register 2 is 0 if register 1 is non-negative. Branch if register 2 is not zero. Otherwise negate register 1.

EX: Put absolute value of register 2 name file .asm vim abs.asm add 1, 8, 0: 0 < 8 = 8, 8 is 0, then you’ve done previous, skip 1 instruction sub 0, 31: number is positive FIX beq 0, ifend sub 0, 32

LOOPING Adss together all even numbers from 1 to 20 incluseve and store answer in register 2 .word 20 lis 3, 0: sets the result to 0 becuase we want to 0, start the loop at 20 and go down. (less code) add 3, 2, 2; line -2 bne 0, -3; line -1 from here, if doesn’t reach 0 we go back to line -3, and come down again jr $31

Use label for us to add new instructions

EX: sample has the address 0x4, which is the location of add 0, $0

lis $2
.word 20
lis $1
.word 2
add $3 $0, $0
top:
	add $3 $3 $2
	sub $2 $2, $1
	bne $2 $0, top
jr $31

label below condition vs above is a loop careful with where you check and put the label…