# Faculty of Computer Science © 2006 CMPUT 229 Why Computer Architecture? An Introduction to CMPUT 229.

## Presentation on theme: "Faculty of Computer Science © 2006 CMPUT 229 Why Computer Architecture? An Introduction to CMPUT 229."— Presentation transcript:

Faculty of Computer Science © 2006 CMPUT 229 Why Computer Architecture? An Introduction to CMPUT 229

© 2006 Department of Computing Science CMPUT 229 Below Your Program High-level language program in C void swap(int v[ ], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } swap: muli\$2, \$5, 4 add\$2, \$4, \$2 lw\$15, 0(\$2) lw\$16, 4(\$2) sw\$16, 0(\$2) sw\$15, 4(\$2) jr\$31 Compiler Assembly language program (for MIPS) 00000000101000010000000000011000 00000000100011100001100000100001 10001100011000100000000000000000 10001100111100100000000000000100 10101100111100100000000000000000 10101100011000100000000000000100 00000011111000000000000000001000 Assembler Binary machine language program (for MIPS) Hennessy-Patterson, pp.7

© 2006 Department of Computing Science CMPUT 229 Trying it out #include void swap(int v[ ], int k); void print_vector(int v[ ]); int main(int argc, char *argv[ ]) { int v[]={1,3,5,7,9,-1}; print_vector(v); swap(v,2); print_vector(v); } void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } void print_vector(int v[]) { int i; for(i=0 ; v[i]>0 ; i++) printf("\t%d ",v[i]); printf("\n"); }

swap: # vars= 8, regs= 2/0, args= 0, extra= 8.frame\$fp,24,\$31.mask0x50000000,-4.fmask0x00000000,0.setnoreorder.cpload\$25.setreorder subu\$sp,\$sp,24.cprestore 0 sw\$fp,20(\$sp) sw\$28,16(\$sp) move\$fp,\$sp sw\$4,24(\$fp) sw\$5,28(\$fp) lw\$2,28(\$fp) move\$3,\$2 sll\$2,\$3,2 lw\$3,24(\$fp) addu\$2,\$2,\$3 lw\$3,0(\$2) sw\$3,8(\$fp) lw\$2,28(\$fp) move\$3,\$2 sll\$2,\$3,2 lw\$3,24(\$fp) addu\$2,\$2,\$3 lw\$3,28(\$fp) move\$4,\$3 sll\$3,\$4,2 lw\$4,24(\$fp) addu\$3,\$3,\$4 addu\$4,\$3,4# page 1 \$ gcc -S swap.c [on a MIPS R12K machine] lw\$3,0(\$4) sw\$3,0(\$2) lw\$2,28(\$fp) move\$3,\$2 sll\$2,\$3,2 lw\$3,24(\$fp) addu\$2,\$2,\$3 addu\$3,\$2,4 lw\$2,8(\$fp) sw\$2,0(\$3)# page 2

swap: # vars= 0, regs= 0/0, args= 0, extra= 0.frame\$sp,0,\$31.mask0x00000000,0.fmask0x00000000,0.setnoreorder.cpload\$25.setreorder sll\$5,\$5,2 addu\$5,\$5,\$4 lw\$2,4(\$5) lw\$3,0(\$5) sw\$2,0(\$5).setnoreorder.setnomacro j\$31 sw\$3,4(\$5).setmacro.setreorder.endswap.rdata.align2 \$ gcc -O3 -S swap.c [on a MIPS R12K machine]

swap: link.w %a6,#-4 move.l 12(%a6),%d0 lsl.l #2,%d0 move.l 8(%a6),%a0 move.l (%a0,%d0.l),-4(%a6) move.l 12(%a6),%d0 move.l %d0,%d1 lsl.l #2,%d1 move.l 8(%a6),%a1 move.l 12(%a6),%d0 lsl.l #2,%d0 add.l 8(%a6),%d0 move.l %d0,%a0 addq.l #4,%a0 move.l (%a0),(%a1,%d1.l) move.l 12(%a6),%d0 lsl.l #2,%d0 add.l 8(%a6),%d0 move.l %d0,%a0 addq.l #4,%a0 move.l -4(%a6),(%a0) unlk %a6 rts \$ gcc -S swap.c [for a 68K machine] swap: link.w %a6,#0 move.l 8(%a6),%a0 move.l 12(%a6),%d0 move.l (%a0,%d0.l*4),%d1 move.l 4(%a0,%d0.l*4),(%a0,%d0.l*4) move.l %d1,4(%a0,%d0.l*4) unlk %a6 rts \$ gcc -O3 -S swap.c [for a 68K machine]

swap:.prologue.body sxt4 r33 = r33 ;; shladd r33 = r33, 2, r32 ;; mov r14 = r33 ;; ld4 r16 = [r14], 4 ;; ld4 r15 = [r14] ;; st4 [r33] = r15 st4 [r14] = r16 br.ret.sptk.many b0.endp swap# \$ gcc -O3 -S swap.c [on an Itanium I machine]

© 2006 Department of Computing Science CMPUT 229 Machine Organization P-Pro bus (64-bit data, 36 bit address, 66 MHz) CPU Interrupt Controler 256-KB L2 Bus interface PCI Bridge PCI I/O Cards PCI I/O Cards PCI I/O Cards PCI Bus PCI Bridge PCI I/O Cards PCI I/O Cards PCI I/O Cards PCI Bus Memory Controller Memory Interleave Unit 1-, 2-, 4-way Interleaved DRAM CullerSinghGupta, pp. 32

© 2006 Department of Computing Science CMPUT 229 Example of SMP machine: Pentium “quad pack” P-Pro bus (64-bit data, 36 bit address, 66 MHz) CPU Interrupt Controler 256-KB L2 Bus interface CPU Interrupt Controler 256-KB L2 Bus interface CPU Interrupt Controler 256-KB L2 Bus interface CPU Interrupt Controler 256-KB L2 Bus interface PCI Bridge PCI I/O Cards PCI I/O Cards PCI I/O Cards PCI Bus PCI Bridge PCI I/O Cards PCI I/O Cards PCI I/O Cards PCI Bus Memory Controller Memory Interleave Unit 1-, 2-, 4-way Interleaved DRAM CullerSinghGupta, pp. 32

© 2006 Department of Computing Science CMPUT 229 A More Complete Story Source file Compiler Assembler file Object file Assembler Linker Source file Compiler Assembler file Object file Assembler Source file Compiler Assembler file Object file Assembler Program library Program library Executable file

© 2006 Department of Computing Science CMPUT 229 When to use Assembly Language? –When you don’t have the tools to program in higher level: new embedded processors compilers that check deadlines for real time system do not exist yet –When the tools fail: Compilers still generate sub-optimal code –When you are building the tools: Compiler designer/builders must know assembly well

© 2006 Department of Computing Science CMPUT 229 Anatomy of an Object File Size and position of other pieces. Machine Code Binary Data Representation. References that must change if the program is moved in memory. Associate addresses with external label. Unresolved references. Compilation information to allow mapping of addresses to source code. Henn-Pat, pp. A-13 COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED

© 2006 Department of Computing Science CMPUT 229 Assembler Features  Data Layout Directives –string directives  Macros  Pseudo Instructions  Conditional Assembling Henn-Pat, pp. A-14/A-17

Download ppt "Faculty of Computer Science © 2006 CMPUT 229 Why Computer Architecture? An Introduction to CMPUT 229."

Similar presentations