Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Organization and Architecture I José Nelson Amaral

Similar presentations


Presentation on theme: "Computer Organization and Architecture I José Nelson Amaral"— Presentation transcript:

1 Computer Organization and Architecture I José Nelson Amaral
CMPUT229 - Fall 2003 Computer Organization and Architecture I José Nelson Amaral CMPUT Computer Organization and Architecture I

2 CMPUT 229 - Computer Organization and Architecture I
In Your Course Package Hennessy, John L., Patterson, David A., Computer Organization and Design: The Hardware/Software Interface, Morgan Kaufmann Pub., San Mateo, CA. (H&P) Hennessy, John L., Patterson, David A., Computer Organization and Design: The Hardware/Software Interface, Morgan Kaufmann Pub., San Mateo, CA. (H&P) Patt, Yale N., and Patel, Sanjay J., Introduction to Computing Systems: from bits & gates to C & Beyond, McGrawHill Press, (P&P) Patt, Yale N., and Patel, Sanjay J., Introduction to Computing Systems: from bits & gates to C & Beyond, McGrawHill Press, (P&P) Goodman, James and Miller, Karen, A Programmer’s View of Computer Architecture with Assembly Language Examples from the MIPS RISC Architecure, Oxford University Press, 1993. (G&M) Goodman, James and Miller, Karen, A Programmer’s View of Computer Architecture with Assembly Language Examples from the MIPS RISC Architecure, Oxford University Press, 1993. (G&M) Bryant, Randal E., O’Hallaron, David, Computer Systems: A Programmer’s Perspective, Prentice Hall, (B&H) Bryant, Randal E., O’Hallaron, David, Computer Systems: A Programmer’s Perspective, Prentice Hall, (B&H) CMPUT Computer Organization and Architecture I

3 CMPUT 229 - Computer Organization and Architecture I
In Your Course Package Hennessy, John L., Patterson, David A., Computer Organization and Design: The Hardware/Software Interface, Morgan Kaufmann Pub., San Mateo, CA. (H&P) Patt, Yale N., and Patel, Sanjay J., Introduction to Computing Systems: from bits & gates to C & Beyond, McGrawHill Press, (P&P) Goodman, James and Miller, Karen, A Programmer’s View of Computer Architecture with Assembly Language Examples from the MIPS RISC Architecure, Oxford University Press, 1993. (G&M) Bryant, Randal E., O’Hallaron, David, Computer Systems: A Programmer’s Perspective, Prentice Hall, (B&H) CMPUT Computer Organization and Architecture I

4 CMPUT 229 - Computer Organization and Architecture I
Your Course Package Source Pages Topic P&H A.1-A.78 MIPS Assembly Reference P&P Introduction P&P Number Representation P&P Digital Logic P&P Von Neumann Architecture H&P MIPS instructions H&P ; Floating Point G&M I/O - polling vs. interrupts G&M Interruption Handling P&P C Fundamentals P&P Variables & Memory Storage B&O Dynamic Memory, Heap P&P Pointers & Arrays B&O Caches & Coding CMPUT Computer Organization and Architecture I

5 Additional Optional Reading
An excellent reference book for the C Language: Harbison, Samuel P., and Steele Jr., Guy, C: A Reference Manual, Prentice Hall, 4th Edition, 1995. An easy to follow reference to MIPS Assembly: Waldron, J., Introduction to RISC Assembly Language Programming, Addison-Wesley, ISBN A more recent and complete book on MIPS Assembbly: Britton, Robert L., MIPS Assembly Language Programming, Prentice Hall, Upper Saddle River, NJ, 2004. CMPUT Computer Organization and Architecture I

6 2000 1998 1990 1994 1988 1980

7 CMPUT 229 - Computer Organization and Architecture I
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) Assembler Binary machine language program (for MIPS) Henn-Pat, pp. 7 CMPUT Computer Organization and Architecture I

8 CMPUT 229 - Computer Organization and Architecture I
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); } 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 Computer Organization and Architecture I

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

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

11 [on a Pentium III machine]
$ gcc -S swap.c [on a Pentium III machine] swap: pushl %ebp movl %esp, %ebp subl $4, %esp movl 12(%ebp), %eax imull $4, %eax, %edx movl 8(%ebp), %eax movl (%eax,%edx), %eax movl %eax, -4(%ebp) imull $4, %eax, %ecx movl 8(%ebp), %edx imull $4, %eax, %eax addl 8(%ebp), %eax addl $4, %eax movl (%eax), %eax movl %eax, (%edx,%ecx) leal 4(%eax), %edx movl -4(%ebp), %eax movl %eax, (%edx) leave ret $ gcc -O3 -S swap.c [on a Pentium III machine] swap: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx pushl %ebx movl 12(%ebp), %eax movl (%edx,%eax,4), %ebx movl 4(%edx,%eax,4), %ecx movl %ecx, (%edx,%eax,4) movl %ebx, 4(%edx,%eax,4) movl (%esp), %ebx leave ret

12 [on an Itanium I machine]
swap: .prologue 2, 2 .vframe r2 mov r2 = r12 ;; .body st8 [r2] = r32 mov r14 = r2 ;; adds r14 = 8, r2 ;; st4 [r14] = r33 mov r14 = r2 adds r16 = 12, r2 ;; ld4 r14 = [r14] ;; sxt4 r15 = r14 addl r14 = 4, r0 ;; setf.sig f6 = r15 setf.sig f7 = r14 ;; xma.l f6 = f6, f7, f0 ;; getf.sig r15 = f6 ld8 r14 = [r2] ;; add r14 = r15, r14 ;; st4 [r16] = r14 add r16 = r15, r14 mov r14 = r2 ;; #page 1 $ gcc -S swap.c [on an Itanium I machine] ld4 r14 = [r14] ;; sxt4 r15 = r14 addl r14 = 4, r0 ;; setf.sig f6 = r15 setf.sig f7 = r14 ;; xma.l f6 = f6, f7, f0 ;; getf.sig r15 = f6 ld8 r14 = [r2] ;; add r14 = r15, r14 ;; adds r14 = 4, r14 ;; st4 [r16] = r14 mov r14 = r2 ;; adds r14 = 8, r2 ;; adds r15 = 4, r14 adds r14 = 12, r2 ;; st4 [r15] = r14 .restore sp mov r12 = r2 br.ret.sptk.many b0 .endp swap# .section .rodata .align 8 # page 2

13 [on an Itanium I machine]
$ gcc -O3 -S swap.c [on an Itanium I 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#

14 CMPUT 229 - Computer Organization and Architecture I
Admin. Information Instructor: Prof. José Nelson Amaral Office: Athabasca 3-42 Phone: Office Hours: Wednesday 10:00-11:00 Wednesday 1:00-2:00 (Open Door Policy --- check published schedule) CMPUT Computer Organization and Architecture I

15 CMPUT 229 - Computer Organization and Architecture I
Important Dates September 15 (Monday) : lab classes start this week TBA : mid-term exam December 03 (Wednesday) : last day of classes December 10 (Wednesday) : final for section A1 (9 AM class) Course work will carry the following weights towards your final grade: Lab. Assignments(using try): 27% Midterm Exam: 35% Final Exam: 38% Homeworks: Zero CMPUT Computer Organization and Architecture I

16 CMPUT 229 - Computer Organization and Architecture I
Honor Code By turning the solution of the homework for grading, I certify that I have worked all the solutions on my own, that I have not copied or transcribed solutions from a classmate, someone outside the class, or from any other source. I also certify that I have not facilitated or allowed any of my classmates to copy my own solutions. I am aware that students are encouraged to discuss the material covered in the class and to work examples together. However, the joint solution of problems assigned as individual homework exercises is not allowed. I am aware that the violation of this honor code constitutes a breach of the trust granted me by the teaching staff, compromises my reputation, and subjects me to the penalties prescribed in Section 26.1 of the University of Alberta 2001/2002 Calendar. CMPUT Computer Organization and Architecture I

17 Some Sad Statistics in Computing Science
21 cases of plagiarism in the 2000/2001 Academic Year: 29 cases of plagiarism in the 2002/2003 Academic Year. CMPUT Computer Organization and Architecture I

18 Late Submission Policy For Labs:
There is no late submission for labs! All deadlines are “drop-dead deadlines”! Deferred exams will be scheduled for early January, and will be different from the final given on the scheduled date. CMPUT Computer Organization and Architecture I

19 CMPUT 229 - Computer Organization and Architecture I
Did I mention? NO Late Submissions!!!! None. At all. CMPUT Computer Organization and Architecture I

20 CMPUT 229 - Computer Organization and Architecture I
Reading Assignment Hennessy Patterson Texbook: Appendix A: Sections A.1 to A.4 and A.9 CMPUT Computer Organization and Architecture I

21 Machine Organization CPU
Interrupt Controler 256-KB L2 Bus interface P-Pro bus (64-bit data, 36 bit address, 66 MHz) PCI Bridge I/O Cards PCI Bus PCI Bridge I/O Cards PCI Bus Memory Controller Memory Interleave Unit 1-, 2-, 4-way Interleaved DRAM CMPUT Computer Organization and Architecture I (See CullerSinghGupta, pp. 32)

22 Example of SMP machine: Pentium “quad pack”
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 P-Pro bus (64-bit data, 36 bit address, 66 MHz) PCI Bridge I/O Cards PCI Bus PCI Bridge I/O Cards PCI Bus Memory Controller Memory Interleave Unit 1-, 2-, 4-way Interleaved DRAM CMPUT Computer Organization and Architecture I (See CullerSinghGupta, pp. 32)

23 Converting Source into Executable Files
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED Henn-Pat, pp. A-4 CMPUT Computer Organization and Architecture I

24 CMPUT 229 - Computer Organization and Architecture I
A More Complete Story Program library Source file Compiler Assembler file Object file Assembler Linker Source file Compiler Assembler Object Executable file Program library CMPUT Computer Organization and Architecture I

25 Converting Source into Executable Files
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED Henn-Pat, pp. A-8 CMPUT Computer Organization and Architecture I

26 The Linker Henn-Pat, pp. A-18
COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED Henn-Pat, pp. A-18 CMPUT Computer Organization and Architecture I

27 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 Computer Organization and Architecture I

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

29 CMPUT 229 - Computer Organization and Architecture I
Assembler Features Data Layout Directives string directives Macros Pseudo Instructions Conditional Assembling Henn-Pat, pp. A-14/A-17 CMPUT Computer Organization and Architecture I

30 CMPUT 229 - Computer Organization and Architecture I
SPIM SPIM is a software simulator that runs programs written for MIPS R2000/R3000 processors. - available - self-contained - has a debugger - provides limited operating system-like services - at least 100 slower than hardware - implements pseudoinstructions - virtual machine: simulates non-delayed branches Features: Henn-Pat, pp. A-38/A-39 CMPUT Computer Organization and Architecture I

31 This is where SPIM error messages appear.
CMPUT Computer Organization and Architecture I Pat-Hen. pp. A-41/A-47 COPYRIGHT 1998 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED

32 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

33 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

34 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

35 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

36 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

37 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

38 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

39 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

40 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

41 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

42 Register Usage Convention
Patt-Hen., pp. A-23 CMPUT Computer Organization and Architecture I

43 CMPUT 229 - Computer Organization and Architecture I
Assembler Syntax comments begin with a sharp sign (#) and run to the end of the line. identifiers are alphanumeric sequences, underbars (_), and dots (.) that do not begin with a number. labels are identifiers placed at the beginning of a line, and followed by a colon. .data item: word 1 .text .globl main main: lw $s3, item Loop: add $t1, $s3, $s3 # $t1  2 * i add $t1, $t1, $t1 # $t1  4 * i add $t1, $t1, $s6 # $t1  Addr(save[i]) lw $t0, 0($t1) # $t0  MEM[save[i]] bne $t0, $s5, Exit # if save[I]  k goto Exit add $s3, $s3, $s4 # i  i + j j Loop # goto Loop Exit:: CMPUT Computer Organization and Architecture I Pat-Hen. pp. A-51

44 CMPUT 229 - Computer Organization and Architecture I
Assembler Directives .data identifies the beginning of the data segment (in this example this segment contains a single word). .word stores the decimal number 1 in 32-bits (4 bytes) .text identifies the beginning of the text segment (where the instructions of the program are stored). .globl main declares the label main global (so that it can be accessed from other files). .data item: word 1 .text .globl main main: lw $s3, item Loop: add $t1, $s3, $s3 # $t1  2 * i add $t1, $t1, $t1 # $t1  4 * i add $t1, $t1, $s6 # $t1  Addr(save[i]) lw $t0, 0($t1) # $t0  MEM[save[i]] bne $t0, $s5, Exit # if save[I]  k goto Exit add $s3, $s3, $s4 # i  i + j j Loop # goto Loop Exit:: CMPUT Computer Organization and Architecture I Pat-Hen. pp. A-52

45 CMPUT 229 - Computer Organization and Architecture I
What’s next? Loading Memory Layout But, before we talk about memory layout, we need to talk about number representation. CMPUT Computer Organization and Architecture I


Download ppt "Computer Organization and Architecture I José Nelson Amaral"

Similar presentations


Ads by Google