MIPS Code Examples and Register Optimization
Classified in Computers
Written on in
English with a size of 3.4 KB
Code in MIPS to add the 4 integer variables: a, b, c, d.
Add e,a,b # a gets b+c or a,b,c # a gets b+c
Add e,e,c # a gets a+dor a,a,c, # a gets a+d
Add e,e,d # a gets a+ eor a,a,e # a gets a+e
Code in MIPS for: f = (g + h) ‐ (i + j);
or #f,.., j are mapped to $s0, ., $s4
add t0,g,h #temp t0=g+hadd $t0,$s1,$s2
add t1,i,j #temp t1=i+jadd $t1,$s3,$s4
sub f,t0,t1 #f=t0-t1sub $s0,$t0,$t1
Why the size of a register is 32 bit?
32 bit occurs frequently and thus in MIPS, it has a special name ‘word’. Size 32 aligns well with the MIPS instruction format.
‘MIPS is Big Endian’ – what does it mean?
Most significant byte at least address of a word.
What are lw and sw instructions used for?
MIPS data transfer instructions with an address to access particular... Continue reading "MIPS Code Examples and Register Optimization" »