1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CS/COE0447 Computer Organization & Assembly Language
The University of Adelaide, School of Computer Science
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 6: MIPS Instruction Set Today’s topic –Control instructions –Procedure call/return 1.
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
Computer Architecture CSCE 350
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
The University of Adelaide, School of Computer Science
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The University of Adelaide, School of Computer Science
CS3350B Computer Architecture Winter 2015 Lecture 4
Procedure call frame: Hold values passed to a procedure as arguments
Lecture 8: MIPS Instruction Set
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
Assembly Language II CPSC 321 Andreas Klappenecker.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Structure - The Instruction Set (2) Goal: Implement Functions in Assembly  When executing a procedure (function in C) the program must follow.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
RISC Concepts, MIPS ISA and the Mini–MIPS project
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
Memory/Storage Architecture Lab Computer Architecture MIPS Instruction Set Architecture ( Supporting Procedures )
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 1.
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Spr 2015, Feb 9... ELEC / Lecture 4 1 ELEC / Computer Architecture and Design Spring 2015 Compiling and Executing Programs.
1 Branches and Procedure Calls Lecture 14 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
The Assembly Process Computer Organization and Assembly Language: Module 10.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
Adapted from Computer Organization and Design, Patterson & Hennessy, UCB ECE232: Hardware Organization and Design Part 8: MIPS Procedures and Recursion.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Lecture 3 Translation.
ECE3055 Computer Architecture and Operating Systems Chapter 2: Procedure Calls & System Software These lecture notes are adapted from those of Professor.
Computer Architecture & Operations I
Lecture 6: Assembly Programs
Computer Architecture Instruction Set Architecture
Computer Architecture Instruction Set Architecture
The University of Adelaide, School of Computer Science
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
CS/COE0447 Computer Organization & Assembly Language
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Lecture 5: Procedure Calls
Computer Organization and Design Assembly & Compilation
COMS 361 Computer Organization
Lecture 6: Assembly Programs
10/6: Lecture Topics C Brainteaser More on Procedure Call
Program Assembly.
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3

2 Topics Register Usage Conventions Stack and Frame Pointers Procedure Calls Creating executables –Assembler, linker, loader –Compilers versus interpreters What does the assembler do for you?

3 Register Usage Convention NAMEREG. NUMBERUSAGE $zero0zero $at1reserved for assembler usage $v0~$v12~3values for results and expression eval. $a0~$a34~7arguments $t0~$t78~15temporaries $s0~$s716~23temporaries, saved $t8~$t924~25more temporaries $k0~$k126~27reserved for OS kernel $gp28global pointer $sp29stack pointer $fp30frame pointer $ra31return address

4 Stack and Frame Pointers Stack pointer ($sp) –Keeps the address to the top of the stack –$29 is reserved for this purpose –Stack grows from high address to low –Typical stack operations are push/pop Procedure frame –Contains saved registers and local variables –“Activation record” Frame pointer ($fp) –Points to the first word of a frame –Offers a stable reference pointer –$30 is reserved for this –Some compilers don’t use $fp

5 Procedure Calls Argument passing –First 4 arguments are passed through $a0~$a3 –More arguments are passed through stack Result passing –First 2 results are passed through $v0~$v1 –More results can be passed through stack Stack manipulations can be tricky and error-prone A programming assignment will involve the stack

6 “C Program” Down to “Numbers” 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 void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } … … … … … … … compiler assembler

7 To Produce an Executable source file.asm/.s source file.asm/.s source file.asm/.s object file.obj/.o object file.obj/.o object file.obj/.o library.lib/.a executable.exe assembler linker

8 Linker

9 An Object File Header –Size and position of other pieces of the file Text segment –Machine codes Data segment –Binary representation of the data in the source Relocation information –Identifies instructions and data words that depend on absolute addresses Symbol table –Keeps addresses of global labels –Lists unresolved references Debugging information –Contains a concise description of the way in which the program was compiled

10 Interpreter vs. Compiler InterpreterCompiler Concept Line-by-line translation and execution Whole program translation and native execution Example Java, BASIC, …C, Fortran, … + Interactive Portable (e.g., Java Virtual Machine) High performance – Low performance Binary not portable to other machines or generations

11 An Assembler Expands macros –Macro is a sequence of operations conveniently defined by a user –A single macro can expand to many instructions Determines addresses and translates source into binary numbers –Record in “symbol table” addresses of labels –Resolve branch targets and complete branch instructions’ encoding –Record instructions that need be fixed after linkage Packs everything in an object file “Two-pass assembler” –To handle forward references

12 Assembler Directives Guides the assembler to properly handle following codes with certain considerations.text –Tells assembler that codes follow.data –Tells assembler that data follow.align –Directs aligning the following items.global –Tells to treat the following symbol as global.asciiz –Tells to handle the following as a “string”

13 Macro Example.data int_str:.asciiz“%d”.text.macroprint_int($arg) la $a0, int_str mov $a1, $arg jal printf.end_macro … print_int($7) la $a0, int_str mov $a1, $7 jal printf To use macros in MARS, need to run it from the command line

14 High-Level Lang. vs. Assembly High-level languageAssembly Example C, Fortran, Java, …- + High productivity – Short description & readability Portability Low productivity – Long description & low readability Not portable – Limited optimization capability in certain cases With proper knowledge and experiences, fully optimized codes can be written

15 Branch and Jump Instructions Review

16 Instruction Format beq, bne PC = PC BranchAddr Without delayed branching (in MARS!!) –PC = PC + BranchAddr BranchAddr = {14{immediate[15]},immediate,2'b0} Two issues: –Assembly  machine code –Execution of the machine code 16-bit immediatertrsop I

17 bne $t0,$s5,exitloop addi $s3,$s3,1 j loop exitloop: add $s6,$s3,$zero 0x x x c 0x BNE machine code in binary: BNE machine code in hex: When BNE instruction is executed (condition true): Next address = PC + BranchAddr Next address = c = … address of the exitloop inst! BranchAddr = {14{immediate[15]},immediate,2'b0} = { , ,00} = = 0x c

18 BranchAddr: Why 2’b0 at the end? BranchAddr might have been: {number,00} = number * 4 (like shifting left by 2) Recall: the immediate field of the instruction contains the number of instructions away the label is Each instruction is 4 bytes, so multiplying by 4 gives you the number of bytes away it is. This is the number to add to the PC to jump to the label. {16{immediate[15]},immediate}

19 BranchAddress: Why 2’b0 at the end? If immediate instead were the number of bytes away the label is, then we would be wasting 2 bits Since all instruction addresses are multiples of 4, the bottom 2 bits are always 00 By not including those bits in the immediate field of the machine code, branch instructions can be used to jump 4 times further away

20 Nice question for an Exam What would change in the previous example, if delayed branching were used in MARS? The immediate value would be 1 less With delayed branching: –PC = PC BranchAddress –The “4” is due to the fact that the PC has already been incremented to point to the next instruction In EG (slide 17): imm would be PC = PC BranchAddress BranchAddress = {14{0}, ,00} = 0x PC = 0x = 0x

21 Instruction Format, cont’d The address of next instruction is obtained by concatenating with PC PC = {PC[31:28],address,2’b0} 26-bit addressopJump

22 0x bne $s4, $s5, ELSE 0x c add $s3, $s2, $s5 0x j EXIT ELSE: 0x sub $s3, $s2, $s5 0x addi $s5, $s5, 1 0x c EXIT: addi $s4,$s4,1 j instruction machine code: Hex: b Look at execution: PC = {PC[31:28],address,00} PC[31:28] = 0000 address = {0000, address, 00} = BIN c HEX The address EXIT stands for!