40 likes | 184 Views
Computer Architecture: A Constructive Approach SMIPS Assembly Example Kermin Elliott Fleming Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology. From C to Assembly . void vvadd( int n, int a[],
E N D
Computer Architecture: A Constructive Approach SMIPS Assembly Example Kermin Elliott Fleming Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology http://csg.csail.mit.edu/SNU
From C to Assembly void vvadd( int n, int a[], int b[], int c[] ){ int i; for ( i = 0; i < n; i++ ) c[i] = a[i] + b[i];} • Prelude • Stack setup • Register Storage • Argument handling • Function Body 00000084 <vvadd>:84: move $t1,$a0 88: move $t0,$zero 8c: blez$t1,bc <vvadd+38> 90: sll$v1,$t0,0x2 94: addu$a0,$v1,$a3 98: addu$v0,$v1,$a1 9c: addu$v1,$v1,$a2 a0: lw$v0,0($v0) a4: lw$v1,0($v1) a8: addu$v0,$v0,$v1 ac: sw$v0,0($a0) b0: addiu$t0,$t0,1 b4: slt$v0,$t0,$t1 b8: bnez$v0,90 <vvadd+c>bc: jr$ra • Postlude • Stack restoration • Register restoration • Result handling • Return http://csg.csail.mit.edu/SNU
Anatomy of a For loop void vvadd( int n, int a[], int b[], int c[] ){ int i; for ( i = 0; i < n; i++ ) c[i] = a[i] + b[i];} • For loops need two branches • Initial check • Loop steady state • Branch immediate is 16-bits • Loops are short 00000084 <vvadd>:84: move $t1,$a0 88: move $t0,$zero 8c: blez$t1,bc <vvadd+38> 90: sll$v1,$t0,0x2 94: addu$a0,$v1,$a3 98: addu$v0,$v1,$a1 9c: addu$v1,$v1,$a2 a0: lw$v0,0($v0) a4: lw$v1,0($v1) a8: addu$v0,$v0,$v1 ac: sw$v0,0($a0) b0: addiu$t0,$t0,1 b4: slt$v0,$t0,$t1 b8: bnez$v0,90 <vvadd+c>bc: jr$ra http://csg.csail.mit.edu/SNU
Computation void vvadd( int n, int a[], int b[], int c[] ){ int i; for ( i = 0; i < n; i++ ) c[i] = a[i] + b[i];} • Manual Pointer Arithmetic 00000084 <vvadd>:84: move $t1,$a0 88: move $t0,$zero 8c: blez$t1,bc <vvadd+38> 90: sll$v1,$t0,0x2 94: addu$a0,$v1,$a3 98: addu$v0,$v1,$a1 9c: addu$v1,$v1,$a2 a0: lw$v0,0($v0) a4: lw$v1,0($v1) a8: addu$v0,$v0,$v1 ac: sw$v0,0($a0) b0: addiu$t0,$t0,1 b4: slt$v0,$t0,$t1 b8: bnez$v0,90 <vvadd+c>bc: jr$ra http://csg.csail.mit.edu/SNU