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

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

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.
Goal: Write Programs in Assembly
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
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 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Assembly Code Example Selection Sort.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
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.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
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
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
MIPS Instruction Set Advantages
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.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 1 In-Class Lab Session (Lab 2)
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
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
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
CMPE 325 Computer Architecture II
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 2.
9/29: Lecture Topics Conditional branch instructions
ECE 15B Computer Organization Spring 2011 Dmitri Strukov Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy,
Csci 136 Computer Architecture II – More on MIPS ISA Xiuzhen Cheng
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
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.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 14, 15 Addressing Mode.
10/1: Lecture Topics Conditional branch instructions –slides from 9/29 set Unconditional jump instructions Instruction encoding.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
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
MIPS Instruction Set Advantages
The University of Adelaide, School of Computer Science
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
CS/COE0447 Computer Organization & Assembly Language
The University of Adelaide, School of Computer Science
MIPS coding.
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
MIPS Instruction Encoding
MIPS Instruction Encoding
Computer Organization and Design Assembly & Compilation
The University of Adelaide, School of Computer Science
COMS 361 Computer Organization
Lecture 6: Assembly Programs
MIPS Coding Continued.
MIPS coding.
10/6: Lecture Topics C Brainteaser More on Procedure Call
Program Assembly.
Presentation transcript:

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

2 Topics Creating executables –Assembler, linker, loader –Compilers versus interpreters What does the assembler do for you? Review of branch and jump instructions

3 “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

4 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

5 Linker

6 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

7 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 –bne $t0,$t1,next_label –next_label:

8 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”

9 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

10 Branch and Jump Instructions Review

11 Instruction Format beq, bne PC = PC BranchAddr BranchAddr = {14{immediate[15]},immediate,2'b0} Two issues: –Assembly  machine code –Execution of the machine code 16-bit immediatertrsop I

12 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 = = … address of the exitloop inst! BranchAddr = {14{immediate[15]},immediate,2'b0} = { , ,00} = = 0x

13 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 PC + 4 to jump to the label. {16{immediate[15]},immediate}

14 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

15 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

16 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!