lecture5

h goto loop use this mapping g s1 h s2 i s3

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: same as: beq $0,$0,label since it always sa4sfies the condi4on. Compiling C if into MIPS • Compile by hand if (i == j) f=g+h; else f=g-h; • Use this mapping: (false) 
 (true) 
 i == j? i != j! i == j! f=g+h f=g-h Exit! f: $s0, g: $s1, h: $s2, i: $s3, j: $s4 Compiling C if into MIPS °  Compile by hand if (i == j) f=g+h; else f=g-h;! (false) 
 (true) 
 i == j? i != j! i == j! f=g+h • Final compiled MIPS code: beq $s3,$s4,True sub $s0,$s1,$s2 j Fin True: add $s0,$s1,$s2 Fin: # # # # f=g-h Exit! branch i==j f=g-h(false) goto Fin f=g+h (true) Loops in C/Assembly •  Simple loop in C; A is an array of ints do { g = g + A[i]; i = i + j; } while (i != h); •  Rewrite this as: Loop: g = g + A[i]; i = i + j; if (i != h) goto Loop; •  Use this mapping: g: $s1, h: $s2, i: $s3, j: $s4, base of A:$s5 Loops in C/Assembly •  Final compiled MIPS code: Loop: sll $t1,$s3,2 #$t1= 4*i add $t1,$t1,$s5 #$t1=addr A lw $t1,0(...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 64 taught by Professor Zheng during the Fall '09 term at UCSB.

Ask a homework question - tutors are online