1 / 4

Computer Architecture: A Constructive Approach SMIPS Assembly Example Kermin Elliott Fleming

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[],

lynley
Download Presentation

Computer Architecture: A Constructive Approach SMIPS Assembly Example Kermin Elliott Fleming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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

  4. 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

More Related