NAMES OF MIPS REGISTERS Registers are numbered from 0 to 31 Each register can be referred to by number or name Number references S0,$1,S2,…30,S31 For now S16-$23>Ss0-Ss7(correspond to"saved"variables) s8-$15>$t0-st7(correspond to temporary variables Later will explain other 16 register names In general, use names to make your code more readable
▪ Registers are numbered from 0 to 31 ▪ Each register can be referred to by number or name. ▪ Number references: ▪$0, $1, $2, … $30, $31 ▪ For now: ▪ $16 - $23 → $s0 - $s7 (correspond to “saved” variables) ▪ $8 - $15 → $t0 - $t7 (correspond to temporary variables) ▪ Later will explain other 16 register names ▪ In general, use names to make your code more readable 11
C, JAVA VARIABLES VS REGISTERS In c(and most High Level Languages)variables declared first and gIven a type Example: int fahr, celsius char a, b, c d ei Each variable can ONlY represent a value of the type it was declared as(cannot mix and match int and char variables In Assembly Language, registers have no type; operation determines how register contents are treated
▪ In C (and most High Level Languages) variables declared first and given a type • Example: int fahr, celsius; char a, b, c, d, e; ▪Each variable can ONLY represent a value of the type it was declared as (cannot mix and match int and char variables). ▪ In Assembly Language, registers have no type; operation determines how register contents are treated. 12
ADDITION AND SUBTRACTION INSTRUCTIONS
13
ADDITION AND SUBTRACTION OF INTEGERS Addition in Assembly Example: add ss0, $s1, $s2(in MIPs) equivalent to a=b + c (in C where C variables台 MIPS registers are:a白S9,b白Ss1,c分Ss2 Subtraction in Assembly Example: sub $s3, $s4, $s5(in MIPS) equivalent to: d =e-f C) where c variables台 MIPS registers are:d台$s3,e台$s4,f台Ss5
▪ Addition in Assembly ▪ Example: add $s0,$s1,$s2 (in MIPS) ▪ Equivalent to: a = b + c (in C) where C variables ⇔ MIPS registers are: a ⇔ $s0, b ⇔ $s1, c ⇔ $s2 ▪ Subtraction in Assembly ▪ Example: sub $s3,$s4,$s5 (in MIPS) ▪ Equivalent to: d = e - f (in C) where C variables ⇔ MIPS registers are: d ⇔ $s3, e ⇔ $s4, f ⇔ $s5 14
ADDITION AND SUBTRACTION OF INTEGERS (CONTD) How to translate the following C statement? a =btct d Break into multiple instructions add sto, Ssl, ss2 temp =b+c add sto, sto,$s3# temp= temp d sub sso, sto, ss4 f a=tel A single C statement may break up into several lines of MIIPS Notice the use of temporary registers-don't want to modify the saved variable registers ss Everything after the hash mark on each line is ignored (comments)
▪How to translate the following C statement? a = b + c + d - e; ▪Break into multiple instructions: add $t0, $s1, $s2 # temp = b + c add $t0, $t0, $s3 # temp = temp + d sub $s0, $t0, $s4 # a = temp - e ▪A single C statement may break up into several lines of MIPS. ▪Notice the use of temporary registers – don’t want to modify the saved variable registers $s. ▪Everything after the hash mark on each line is ignored (comments) 15