faculty of computer science © 2006 cmput 229 why computer architecture? an introduction to cmput...
TRANSCRIPT
Faculty of Computer Science
CMPUT 229 © 2006
Why Computer Architecture?
An Introduction to CMPUT 229
© 2006
Department of Computing Science
CMPUT 229
Organization of a Computer
Clements, pp.20
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
Structure of a Computer
Clements, pp.21
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
Stored-Program Computer
Clements, pp.21
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
A Personal-Computer (PC) Motherboard
Clements, pp.22
COPYRIGHT 2006 OXFORD UNIVERSITY PRESS ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
Below Your Program
High-levellanguage
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, 4add $2, $4, $2lw $15, 0($2)lw $16, 4($2)sw $16, 0($2)sw $15, 4($2)jr $31
Compiler
Assemblylanguageprogram
(for MIPS)00000000101000010000000000011000000000001000111000011000001000011000110001100010000000000000000010001100111100100000000000000100101011001111001000000000000000001010110001100010000000000000010000000011111000000000000000001000
Assembler
Binarymachinelanguageprogram
(for MIPS)
Hennessy-Patterson, pp.7
© 2006
Department of Computing Science
CMPUT 229
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");}
swap:# vars= 8, regs= 2/0, args= 0, extra= 8
.frame $fp,24,$31
.mask 0x50000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload$25
.set reordersubu $sp,$sp,24.cprestore 0sw $fp,20($sp)sw $28,16($sp)move $fp,$spsw $4,24($fp)sw $5,28($fp)lw $2,28($fp)move $3,$2sll $2,$3,2lw $3,24($fp)addu $2,$2,$3lw $3,0($2)sw $3,8($fp)lw $2,28($fp)move $3,$2sll $2,$3,2lw $3,24($fp)addu $2,$2,$3lw $3,28($fp)move $4,$3sll $3,$4,2lw $4,24($fp)addu $3,$3,$4addu $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,$2sll $2,$3,2lw $3,24($fp)addu $2,$2,$3addu $3,$2,4lw $2,8($fp)sw $2,0($3) # page 2
swap:# vars= 0, regs= 0/0, args= 0, extra= 0
.frame $sp,0,$31
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.cpload$25
.set reordersll $5,$5,2addu $5,$5,$4lw $2,4($5)lw $3,0($5)sw $2,0($5).set noreorder.set nomacroj $31sw $3,4($5).set macro.set reorder
.end swap
.rdata
.align 2
$ 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 2, 2.vframe r2mov r2 = r12 ;;.bodyst8 [r2] = r32mov r14 = r2 ;;adds r14 = 8, r2 ;;st4 [r14] = r33mov r14 = r2adds r16 = 12, r2 ;;mov r14 = r2 ;;adds r14 = 8, r2 ;;ld4 r14 = [r14] ;;sxt4 r15 = r14addl r14 = 4, r0 ;;setf.sig f6 = r15setf.sig f7 = r14 ;;xma.l f6 = f6, f7, f0 ;;getf.sig r15 = f6ld8 r14 = [r2] ;;add r14 = r15, r14 ;;ld4 r14 = [r14] ;;st4 [r16] = r14mov r14 = r2 ;;adds r14 = 8, r2 ;;ld4 r14 = [r14] ;;sxt4 r15 = r14addl r14 = 4, r0 ;;setf.sig f6 = r15setf.sig f7 = r14 ;;xma.l f6 = f6, f7, f0 ;;getf.sig r15 = f6ld8 r14 = [r2] ;;add r16 = r15, r14mov r14 = r2 ;; #page 1adds r14 = 8, r2 ;;
$ gcc -S swap.c[on an Itanium I machine]
ld4 r14 = [r14] ;;sxt4 r15 = r14addl r14 = 4, r0 ;;setf.sig f6 = r15setf.sig f7 = r14 ;;xma.l f6 = f6, f7, f0 ;;getf.sig r15 = f6ld8 r14 = [r2] ;;add r14 = r15, r14 ;;adds r14 = 4, r14 ;;ld4 r14 = [r14] ;;st4 [r16] = r14mov r14 = r2 ;;adds r14 = 8, r2 ;;ld4 r14 = [r14] ;;sxt4 r15 = r14addl r14 = 4, r0 ;;setf.sig f6 = r15setf.sig f7 = r14 ;;xma.l f6 = f6, f7, f0 ;;getf.sig r15 = f6ld8 r14 = [r2] ;;add r14 = r15, r14 ;;adds r15 = 4, r14mov r14 = r2 ;;adds r14 = 12, r2 ;;ld4 r14 = [r14] ;;st4 [r15] = r14.restore spmov r12 = r2br.ret.sptk.many b0.endp swap#.section .rodata.align 8 # page 2
swap:.prologue.bodysxt4 r33 = r33 ;;shladd r33 = r33, 2, r32 ;;mov r14 = r33 ;;ld4 r16 = [r14], 4 ;;ld4 r15 = [r14] ;;st4 [r33] = r15st4 [r14] = r16br.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
InterruptControler
256-KBL2
Bus interface
PCIBridge
PCII/O
Cards
PCII/O
Cards
PCII/O
Cards
PC
I B
us
PCIBridge
PCII/O
Cards
PCII/O
Cards
PCII/O
Cards
PC
I B
us
MemoryController
Memory Interleave Unit
1-, 2-, 4-wayInterleaved
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
InterruptControler
256-KBL2
Bus interface
CPU
InterruptControler
256-KBL2
Bus interface
CPU
InterruptControler
256-KBL2
Bus interface
CPU
InterruptControler
256-KBL2
Bus interface
PCIBridge
PCII/O
Cards
PCII/O
Cards
PCII/O
Cards
PC
I B
us
PCIBridge
PCII/O
Cards
PCII/O
Cards
PCII/O
Cards
PC
I B
us
MemoryController
Memory Interleave Unit
1-, 2-, 4-wayInterleaved
DRAM
CullerSinghGupta, pp. 32
© 2006
Department of Computing Science
CMPUT 229
Converting Source into Executable Files
Henn-Pat, pp. A-4
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
A More Complete Story
Sourcefile Compiler
Assemblerfile
ObjectfileAssembler
Linker
Sourcefile Compiler
Assemblerfile
ObjectfileAssembler
Sourcefile Compiler
Assemblerfile
ObjectfileAssembler
Programlibrary
Programlibrary
Executablefile
© 2006
Department of Computing Science
CMPUT 229
Converting Source into Executable Files
Henn-Pat, pp. A-8
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
© 2006
Department of Computing Science
CMPUT 229
The Linker
Henn-Pat, pp. A-18COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED
© 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 positionof other pieces.
Machine Code
Binary DataRepresentation.
References that must changeif the program is moved
in memory.
Associate addresseswith external label.
Unresolved references.
Compilation informationto allow mapping of
addresses to source code.
Henn-Pat, pp. A-13COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED