The Assembly Process Computer Organization and Assembly Language: Module 10.

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

Branches Two branch instructions:
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.
Statement Format MIPS assembly language statements have the following format label: opcode operand,operand,operand # comment Label identifies the statement.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
Assembly Language Working with the CPU.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
Machine Independent Assembler Features
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.
1 Registers and MAL - Part I. Motivation So far there are some details that we have ignored instructions can have different formats most computers have.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
The Assembly Process Basically how does it all work.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
MIPS Assembler Programming
RISC Concepts, MIPS ISA and the Mini–MIPS project
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Computer Architecture and Design – ECEN 350 Part 4 [Some slides adapted from M. Irwin, D. Paterson and others]
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
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 Organization Instructions Language of The Computer (MIPS) 2.
ECE 15B Computer Organization Spring 2011 Dmitri Strukov Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy,
CENG 311 Instruction Representation
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
The MIPS Processor Computer Organization The MIPS Processor Appendix A.
EE 3755 Datapath Presented by Dr. Alexander Skavantzos.
The Assembly Process Basically why does it all work.
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
Compiling examples in MIPS
Computer Architecture & Operations I
CSCI206 - Computer Organization & Programming
Prof. Hsien-Hsin Sean Lee
Example Addiu $t1 $r0 3 Addiu $t1 $t1 5 Addiu $t1 $t1 7.
MIPS Coding Continued.
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Science 210 Computer Organization
Computer Organization and Design Instruction Sets
MIPS coding.
Computer Science 210 Computer Organization
CSCI206 - Computer Organization & Programming
MPIS Instructions Functionalities of instructions Instruction format
MIPS Instructions.
MIPS Instruction Encoding
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
MIPS coding.
Computer Organization and Design Assembly & Compilation
Introduction to Micro Controllers & Embedded System Design
Flow of Control -- Conditional branch instructions
Flow of Control -- Conditional branch instructions
MIPS Coding Continued.
MIPS coding.
Program Assembly.
Presentation transcript:

The Assembly Process Computer Organization and Assembly Language: Module 10

Machine Code Generation u Assembling a program entails translating the assembly language into binary machine code u This requires more than simply mapping assembly instructions to machine instructions  Each instruction is bound to an address  Labels are bound to addresses  Assembly instructions which refer to labels generate machine instructions which contain the label's address  Pseudo-instructions are translated into one or more machine instructions

Instruction Format addi $13,$7, bits5 bits 16 bits opcode add $13,$7,$8 immediate operand opcode extended opcode (see Appendix A of Patterson & Hennesy for complete details )

The symbol table u The assembler scans the source code and generates the appropriate bit string for each line encountered u The assembler must remember  what memory locations have been allocated  to which address each label is bound u A symbol table is a list of (label, address) pairs u When the data and text segments have been generated, they are stored as an executable file u The file is used by a program called the loader to initialize memory to the appropriate state before execution

Instructions u The.text directive tells the assembler that the lines which follow are instructions.  By default, the text segment starts at 0x u In some cases, a symbol may not have an assigned address yet when the assembler scans the line where it belongs  A second pass through the code can update instructions containing unresolved labels  Maintain a list of addresses in which each unresolved label appears  When the labeled is added to the symbol table, all locations in the corresponding list are updated to hold the address associated with the label

Pseudo-instructions PseudoActual machine implementation addadd, addi, addu, or addiu mulmult and mflo divdiv and mflo (extra for div by zero check) remdiv and mfhi (extra for div by zero check) lilui [and ori] lalui and ori moveori with $0

Branch offset in the MIPS R2000 u In machine code, the target address in a branch must be specified as an offset from the address of the branch. u During execution, this offset is simply added to the program counter to fetch the next instruction  PC contains the address  Offset is measured in words, not bytes PC_NEW = offset*4 + PC_OLD u To calculate the offset, the assembler uses the formula: offset = (target instruction address – (branch instruction address))/4

Branch offset calculation u The offset is stored in the instruction as a word offset rather than a byte offset.  Instructions are only stored at word boundaries  For both target and branch instruction, the least two bits of the address are zero u An offset maybe negative  If the target instruction preceded the branch instruction u The offset is stored in the 16-bit immediate field  This means the branch can only jump about 2 15 instructions before or after the current address  2 15 instructions (words) = 2 17 bytes

Branch offset calculation [0x ] 0x1440ffe6 bne $2, $0, -104 [__start-0x ]; 44: bnez $v0, __start u An entry in the SPIM instruction list orignal assembly code line number in source file offset calculation, in bytes ignores PC increment offset in bytes (__start = 0x ) 0x – (0x ) = machine code stored offset ffe6 = -26 = -104/4 instruction address

Jump target calculation u The jump instruction has two forms  Pseudo-direct, for j and jal  Register direct for jr and jalr  jr and jalr specify a register containing the address to be loaded into the PC  j and jal specify most of the address of the target within the instruction.  However, they have a range of at most one- sixteenth of the memory space fedcba fedcba

Jump target calculation u The target address is a 32 bit quantity  Since all word addresses are multiples of 4 there is no need to store the last two bits  The jump instruction format has 26 bits for the target address  The remaining 6 bits of the instruction are used for the opcode  The highest-order 4 bits of the target are taken from the address currently stored in the program counter PC opcodeJump target bits (26) 00

Jump Target Calculation  jump instructions have a range of 2 26 words or 2 26 x 2 2 =2 28 bytes  This range is NOT symmetric about the jump instruction fedcba fedcba x x x0fffff7c

Program relocation u It is possible that program modules are developed separately by individual programmers. When these programs are to be loaded into memory they should not be assigned overlapping memory space. u To handle this problem, the modules have to be relocated  relative addresses are relocatable  Any absolute references must be "fixed" by the loader  Use a logical base address known at load time  Absolute addresses are stored as offsets from this TBD base

From source to executable compiler assembler linker loader memory exe obj lib asm high-level source code

Some examples of assembling code.data a1:.word 3 a2:.word 16, 16, 16, 16 a3:.word 5.text __start: la $6, a2 loop: lw $7, 4($6) mul $9, $10, $7 b loop li $v0, 10 syscall

Some examples of assembling code Symbol Table symboladdress a a a __start loop Memory map of data section addresscontents c data a1:.word 3 a2:.word 16, 16, 16, 16 a3:.word 5.text __start: la $6, a2 loop: lw $7, 4($6) mult $9, $10, $7 b loop li $v0, 10 syscall

Translate pseudo-instructions lui $6, $6, 0x1000 ori $6, $6, 0x0004 lw $7, 4($6) mult $10, $7 mflo $9 b loop ori $v0, $0, 10 syscall la $6, a2 loop: lw $7, 4($6) mul $9, $10, $7 b loop li $v0, 10 syscall

Translate to machine code lui $6, 0x1000 ori $6, 0x0004 lw $7, 4($6) mult $10, $7 mflo $9 b loop ori $v0, $0, 10 syscall address contents c (lui) c (ori) cc (lw) c 012a 0018 (mult) (mflo) xxxx (beq) a (ori) c c (syscall)

Resolve relative references lui $6, 0x1000 ori $6, 0x0004 lw $7, 4($6) mult $10, $7 mflo $9 b loop ori $v0, $0, 10 syscall address contents c c cc c 012a fffd (-3) a c c [0x (0x400014)]/4 = -12/4 = -3 = 0xfffd