Lecture 11 How assembler works

Slides:



Advertisements
Similar presentations
Target Code Generation
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
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
ELEN 468 Advanced Logic Design
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
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
The Assembly Language Level
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
An introduction to systems programming
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Implementation of a Stored Program Computer
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Computer Systems – Machine & Assembly code. Objectives Machine Code Assembly Language Op-code Operand Instruction Set.
The Assembly Process Computer Organization and Assembly Language: Module 10.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
Lecture 3 Translation.
Computer Architecture & Operations I
Computer Architecture & Operations I
Component 1.6.
Computer Architecture Instruction Set Architecture
CC410: System Programming
Computer Architecture Instruction Set Architecture
ELE2MIC Friday Lecture Venue Change
System Programming and administration
Morgan Kaufmann Publishers
MIPS Coding Continued.
ELEN 468 Advanced Logic Design
Chapter 3 Machine Language and Assembly Language.
Chapter 3 Machine Language and Assembly Language.
A Closer Look at Instruction Set Architectures
The University of Adelaide, School of Computer Science
Computer Science 210 Computer Organization
CS/COE0447 Computer Organization & Assembly Language
Assembler Design Options
BIC 10503: COMPUTER ARCHITECTURE
Chapter 7 LC-2 Assembly Language.
Instructions - Type and Format
Computer Science 210 Computer Organization
Lecture 2 Data representation
Computer Programming Machine and Assembly.
Assembler CASE Tool.
CSCI206 - Computer Organization & Programming
Computer Architecture & Operations I
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
MIPS Instruction Encoding
The University of Adelaide, School of Computer Science
Loaders and Linkers.
Chapter 8 Central Processing Unit
MIPS Instruction Encoding
Lecture 8 Data structures
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Mastering Memory Modes
MIPS Coding Continued.
Lecture 6 CdM-8 CPU overview
An introduction to systems programming
Target Code Generation
Program Assembly.
Lecture 7 Separate compilation
Location Counter (LC) = 0 while line of code <> END if ORG
Presentation transcript:

Lecture 11 How assembler works Computing platforms Novosibirsk State University University of Hertfordshire D. Irtegov, A.Shafarenko 2018

CdM-8 Opcodes Alu 2-op add, sub, adc, mov S0=0 Fun 2-op Rs Rd Alu 1-op inc, dec, not, neg S0=1 S1=00 Fun 1-op Rd S0=1 S1=01 d Rs Rd ld/st

Full list of CdM-8 instructions

How CdM-8 assembler work Two passes Allocation pass For each line of code, determine Is this line labelled? (yes -> rememver label) Is this line an instruction or dc/ds directive? (yes -> advance * by size of bit-string) No actual code is generated on this pass, only lengths of bit-strings are calculated Generation pass For each line, substitute values for labels and calculate expressions Generate bit-strings for instructions and instruction operands Generate bit-strings (values) for dc directives Generate zero-flled bit-string for ds directve

Why two passes? Because labels can be referenced before they are defined dec r0 jle done # loop body done: # continue after loop body

Single-pass assemblers For every line of code Line has a label? (yes -> remember it in symbol table) Label mentioned in cross-reference table? (yes -> scan all references and substitute a value) Line references a label? (yes -> remember it in cross-reference table) Is referenced label already defined? (yes -> substitute value of the label) (no -> allocate a placeholder) Generate code or data, probably using placeholders Single-pass assemblers are faster, but more complex And they consume more memory they need to store code with placeholders

Linkers Conceptually, assembler+linker are similar to two-phase single-pass assembler Assembler compiling a code with external (unresolved) references must emit some code But it cannot emit finished code. It must use placeholders for references to external and relocatable labels And it must build a cross-reference table for every external label And it must build a cross-reference (relocation) table for every relocatable label

CdM-8 object file (listing and file itself)

In CdM-8, object files contain no tables Just lists of symbols and references And hexadecimal representation of code, data and placeholders So they are easy to read and easy to parse by Python “Real” computing platforms use binary object files Symbol and cross-reference tables are actual tables with headers, binary values and offsets

Multi-pass assemblers In some Platform 2 (ISA), instructions can have variable length For example, branch instruction can have several forms: With byte offset for address (can branch +127 bytes forward or 128 back) With 16-bit offset With 32-bit offset With 64-bit offset x86/x64 ISA is example of such Platform 2 When assembler compiles such instruction, It cannot know which form to use, so it must allocate longest possible placeholder But when it finds a label definition, it can select a shorter form But then all labels defined after this instruction - … - !!!

Why multi-pass? Because, after you select shorter form for one branch instruction, you might find that you can select a shorter form for some other branches So, you must reassemble the program until no shorter form for every label-referencing instruction can be found Usually, two or three passes are sufficient, but for big program you might need more passes For external labels, assembler must use longest possible form in any case.