Faculty of Computer Science Why Computer Architecture An

  • Slides: 21
Download presentation
Faculty of Computer Science Why Computer Architecture? An Introduction to CMPUT 229 Add footer

Faculty of Computer Science Why Computer Architecture? An Introduction to CMPUT 229 Add footer here 3/5/2021 © 2006

Department of Computing Science Organization of a Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL

Department of Computing Science Organization of a Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED Add footer here Clements, pp. 203/5/2021 © 2006

Department of Computing Science Structure of a Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL

Department of Computing Science Structure of a Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED Add footer here Clements, pp. 213/5/2021 © 2006

Department of Computing Science Stored-Program Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED

Department of Computing Science Stored-Program Computer COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED Add footer here Clements, pp. 213/5/2021 © 2006

Department of Computing Science A Personal-Computer (PC) Motherboard COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL

Department of Computing Science A Personal-Computer (PC) Motherboard COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED Add footer here 3/5/2021 Clements, pp. 22 © 2006

Department of Computing Science Below Your Program High-level void swap(int v[ ], int k)

Department of Computing Science Below Your Program High-level void swap(int v[ ], int k) language { program in C int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } Compiler Assembler 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 0000101000000011000 Binary 0000100011100000100001 1000110000000000 machine 100011110010000000100 language 101011001111001000000000 program 10101100010000000100 (for MIPS) 000000111110000000001000 CMPUT 229 Assembly language program (for MIPS) Hennessy-Patterson, pp. 7 © 2006

Department of Computing Science Trying it out #include <stdio. h> void swap(int v[ ],

Department of Computing Science Trying it out #include <stdio. h> 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"); } } CMPUT 229 © 2006

swap: # vars= 8, regs= 2/0, args= 0, extra= 8. frame $fp, 24, $31.

swap: # vars= 8, regs= 2/0, args= 0, extra= 8. frame $fp, 24, $31. mask 0 x 50000000, -4. fmask 0 x 0000, 0. set noreorder. cpload$25. set reorder subu $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, $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, $3 lw $3, 28($fp) move $4, $3 sll $3, $4, 2 lw $4, 24($fp) addu $3, $4 addu $4, $3, 4 # page 1 $ gcc -S swap. c [on a MIPS R 12 K machine] lw sw lw move sll lw addu lw sw CMPUT 229 $3, 0($4) $3, 0($2) $2, 28($fp) $3, $2 $2, $3, 24($fp) $2, $3 $3, $2, 4 $2, 8($fp) $2, 0($3) # page 2

$ gcc -O 3 -S swap. c [on a MIPS R 12 K machine]

$ gcc -O 3 -S swap. c [on a MIPS R 12 K machine] swap: # vars= 0, regs= 0/0, args= 0, extra= 0. frame $sp, 0, $31. mask 0 x 0000, 0. fmask 0 x 0000, 0. set noreorder. cpload$25. set reorder sll $5, 2 addu $5, $4 lw $2, 4($5) lw $3, 0($5) sw $2, 0($5). set noreorder. set nomacro j $31 sw $3, 4($5). set macro. set reorder. end swap. rdata. align 2 CMPUT 229

$ gcc -S swap. c [for a 68 K machine] swap: link. w %a

$ gcc -S swap. c [for a 68 K machine] swap: link. w %a 6, #-4 move. l 12(%a 6), %d 0 lsl. l #2, %d 0 move. l 8(%a 6), %a 0 move. l (%a 0, %d 0. l), -4(%a 6) move. l 12(%a 6), %d 0 move. l %d 0, %d 1 lsl. l #2, %d 1 move. l 8(%a 6), %a 1 move. l 12(%a 6), %d 0 lsl. l #2, %d 0 add. l 8(%a 6), %d 0 move. l %d 0, %a 0 addq. l #4, %a 0 move. l (%a 0), (%a 1, %d 1. l) move. l 12(%a 6), %d 0 lsl. l #2, %d 0 add. l 8(%a 6), %d 0 move. l %d 0, %a 0 addq. l #4, %a 0 move. l -4(%a 6), (%a 0) unlk %a 6 rts $ gcc -O 3 -S swap. c [for a 68 K machine] swap: link. w %a 6, #0 move. l 8(%a 6), %a 0 move. l 12(%a 6), %d 0 move. l (%a 0, %d 0. l*4), %d 1 move. l 4(%a 0, %d 0. l*4), (%a 0, %d 0. l*4) move. l %d 1, 4(%a 0, %d 0. l*4) unlk %a 6 rts CMPUT 229

swap: . prologue 2, 2. vframe r 2 mov r 2 = r 12

swap: . prologue 2, 2. vframe r 2 mov r 2 = r 12 ; ; . body st 8 [r 2] = r 32 mov r 14 = r 2 ; ; adds r 14 = 8, r 2 ; ; st 4 [r 14] = r 33 mov r 14 = r 2 adds r 16 = 12, r 2 ; ; mov r 14 = r 2 ; ; adds r 14 = 8, r 2 ; ; ld 4 r 14 = [r 14] ; ; sxt 4 r 15 = r 14 addl r 14 = 4, r 0 ; ; setf. sig f 6 = r 15 setf. sig f 7 = r 14 ; ; xma. l f 6 = f 6, f 7, f 0 ; ; getf. sig r 15 = f 6 ld 8 r 14 = [r 2] ; ; add r 14 = r 15, r 14 ; ; ld 4 r 14 = [r 14] ; ; st 4 [r 16] = r 14 mov r 14 = r 2 ; ; adds r 14 = 8, r 2 ; ; ld 4 r 14 = [r 14] ; ; sxt 4 r 15 = r 14 addl r 14 = 4, r 0 ; ; setf. sig f 6 = r 15 setf. sig f 7 = r 14 ; ; xma. l f 6 = f 6, f 7, f 0 ; ; getf. sig r 15 = f 6 ld 8 r 14 = [r 2] ; ; add r 16 = r 15, r 14 mov r 14 = r 2 ; ; #page 1 adds r 14 = 8, r 2 ; ; $ gcc -S swap. c [on an Itanium I machine] CMPUT 229 ld 4 r 14 = [r 14] ; ; sxt 4 r 15 = r 14 addl r 14 = 4, r 0 ; ; setf. sig f 6 = r 15 setf. sig f 7 = r 14 ; ; xma. l f 6 = f 6, f 7, f 0 ; ; getf. sig r 15 = f 6 ld 8 r 14 = [r 2] ; ; add r 14 = r 15, r 14 ; ; adds r 14 = 4, r 14 ; ; ld 4 r 14 = [r 14] ; ; st 4 [r 16] = r 14 mov r 14 = r 2 ; ; adds r 14 = 8, r 2 ; ; ld 4 r 14 = [r 14] ; ; sxt 4 r 15 = r 14 addl r 14 = 4, r 0 ; ; setf. sig f 6 = r 15 setf. sig f 7 = r 14 ; ; xma. l f 6 = f 6, f 7, f 0 ; ; getf. sig r 15 = f 6 ld 8 r 14 = [r 2] ; ; add r 14 = r 15, r 14 ; ; adds r 15 = 4, r 14 mov r 14 = r 2 ; ; adds r 14 = 12, r 2 ; ; ld 4 r 14 = [r 14] ; ; st 4 [r 15] = r 14. restore sp mov r 12 = r 2 br. ret. sptk. many b 0. endp swap#. section. rodata. align 8 # page 2

$ gcc -O 3 -S swap. c [on an Itanium I machine] swap: .

$ gcc -O 3 -S swap. c [on an Itanium I machine] swap: . prologue. body sxt 4 r 33 = r 33 ; ; shladd r 33 = r 33, 2, r 32 ; ; mov r 14 = r 33 ; ; ld 4 r 16 = [r 14], 4 ; ; ld 4 r 15 = [r 14] ; ; st 4 [r 33] = r 15 st 4 [r 14] = r 16 br. ret. sptk. many b 0. endp swap# CMPUT 229

Department of Computing Science Machine Organization CPU Interrupt Controler 256 -KB L 2 Bus

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

Department of Computing Science Example of SMP machine: Pentium “quad pack” CPU Interrupt Controler

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

Department of Computing Science Converting Source into Executable Files COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS,

Department of Computing Science Converting Source into Executable Files COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED Henn-Pat, pp. A-4 CMPUT 229 © 2006

Department of Computing Science A More Complete Story Source file Compiler Assembler file Assembler

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

Department of Computing Science Converting Source into Executable Files COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS,

Department of Computing Science Converting Source into Executable Files COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED Henn-Pat, pp. A-8 CMPUT 229 © 2006

Department of Computing Science The Linker COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS

Department of Computing Science The Linker COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED CMPUT 229 Henn-Pat, pp. A-18 © 2006

Department of Computing Science When to use Assembly Language? – When you don’t have

Department of Computing Science 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 CMPUT 229 © 2006

Department of Computing Science Anatomy of an Object File References that must change if

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

Department of Computing Science Assembler Features Data Layout Directives – string directives Macros Pseudo

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