Computer Science 210 Computer Organization More on Assembler.

Slides:



Advertisements
Similar presentations
Target Code Generation
Advertisements

Chapter 7 Introduction to LC-3 Assembly Language Assembly Language Assembly Process Using the Editor & Simulator for Assembly Language Programming.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Introduction to Computing Systems from bits & gates to C & beyond Chapter 7 LC-2 Assembly Language.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Chapter 7 Assembly Language. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 7-2 Human-Readable Machine Language.
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
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++
System Programming Mr. M. V. Nikum (B.E.I.T). Introduction What is System? System is the collection of various components Ex:- College is a system What.
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Chapter 6: Machine dependent Assembler Features
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
Chapters 4 & 5: LC-3 Computer Architecture Machine Instructions Assembly language Programming in Machine and Assembly Language.
Introduction to Computer Engineering CS/ECE 252, Spring 2007 Prof. Mark D. Hill Computer Sciences Department University of Wisconsin – Madison.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Chapter 7 LC-3 Assembly Language. 2 College of Charleston, School of Science and Mathematics Dr. Anderson, Computer Science CS 250 Comp. Org. & Assembly.
MIPS coding. SPIM Some links can be found such as:
Introduction to Computing Systems and Programming Assembly Language.
Computer Science 210 Computer Organization Introduction to Subroutines.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Introduction to Computer Engineering CS/ECE 252, Fall 2007 Prof. Mark D. Hill Computer Sciences Department University of Wisconsin – Madison.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Science 210 Computer Organization Overview of Assembly Language.
Chapter 7 Assembly Language. 7-2 Human-Readable Machine Language Computers like ones and zeros… Humans like symbols… Assembler is a program that turns.
G.Umamaheswari Lect/IT R.M.D.EC system software
The Assembly Process Computer Organization and Assembly Language: Module 10.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Lecture 3 Translation.
Compsci 210 Tutorial Five.
The Little man computer
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Chapter 5- Assembling , Linking, and Executing Programs
Chapter 7 Assembly Language
Chapter 7 & 9.2 Assembly Language
Chapter 7 Assembly Language
Computer Science 210 Computer Organization
Computer Science 210 Computer Organization
and Executing Programs
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Machine Independent Features
Computer Science 210 Computer Organization
Introduction to Computer Engineering
Computer Science 210 Computer Organization
Chapter 7 Assembly Language
Chapter 7 LC-2 Assembly Language.
Computer Science 210 Computer Organization
COSC121: Computer Systems
Introduction to Computer Engineering
The Assembly Language Level
Chapter 7 Assembly Language
Introduction to Computer Engineering
Chapter 7 Assembly Language An Hong 2016 Fall
Chapter 6 Programming the basic computer
Target Code Generation
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Introduction to Computer Engineering
Location Counter (LC) = 0 while line of code <> END if ORG
Chapter 7 Assembly Language
Presentation transcript:

Computer Science 210 Computer Organization More on Assembler

Human-Readable Machine Language Computers like 1s and 0s: People like symbols: ADD R1, R1, #1 ; Increment R1 The assembler makes this happen!

Example: diff = first - second ;; Author: Ken Lambert ;; This program subtracts the number in the variable SECOND from FIRST ;; and stores the result in DIFF ;; Pseudocode design: ; diff = first - second.ORIG x3000 ;; Register usage: ; R0 = first ; R1 = second ; R2 = diff ; Program code LD R0, FIRST LD R1, SECOND NOT R1, R1 ADD R1, R1, #1 ADD R2, R0, R1 ST R2, DIFF HALT ; Data variables FIRST.BLKW 1 SECOND.BLKW 1 DIFF.BLKW 1.END

The Assembly Process Convert the program in the source (.asm) file to an executable file (.obj) for the LC3 simulator First pass: Scan program file Find all labels and calculate their addresses, creating a symbol table Second pass: Convert instructions to machine language, using the symbol table

First Pass: Construct the Symbol Table 1.Find the.ORIG statement, which tells us the address of the first instruction. Initialize location counter (LC), which keeps track of the current instruction. 2.For each non-empty line in the program: a)If line begins with label, add label and LC to symbol table. b)Increment LC. –NOTE: If statement is.BLKW or.STRINGZ, increment LC by the number of words allocated. 3.Stop when.END statement is reached. NOTE: A line that contains only a comment is considered an empty line.

Example Symbol Table Code in subtract.asmTable in subtract.sym LD R0, FIRST LD R1, SECOND NOT R1, R1 ADD R1, R1, #1 ADD R2, R0, R1 ST R2, DIFF HALT FIRST.BLKW 1 SECOND.BLKW 1 DIFF.BLKW 1 // Symbol table // Scope level 0: //Symbol Name Page Address // //FIRST 3007 //SECOND 3008 //DIFF 3009

Second Pass: Generate Machine Code For each executable assembly language statement, generate the corresponding machine language instruction If operand is a label, look up the address from the symbol table Potential errors to detect and flag: Improper number or type of arguments ex: NOTR1,#7 ADDR1,R2 ADDR3,R3,NUMBER Immediate argument too large ex: ADDR1,R2,#1023 Address (associated with label) more than 256 from instruction; can’t use PC-relative addressing mode

Object File Format An LC-3 object file contains Starting address (location where program must be loaded), followed by… Machine language instructions

Multiple Object Files An object file is not necessarily a complete program. system-provided library routines code blocks written by multiple developers For LC-3 simulator, we can load multiple object files into memory, then start executing at a desired address. system routines, such as keyboard input, are loaded automatically loaded into “system memory,” below x3000 user code should be loaded between x3000 and xFDFF each object file includes a starting address be careful not to load overlapping object files In LC3, first file contains the program Remaining files contain data (run lc3convert –b16 or –b2)

The Loader Loading is the process of copying an executable image into memory more sophisticated loaders are able to relocate images to fit into available memory must readjust branch targets, load/store addresses

The Linker Linking is the process of resolving symbols between independent object files suppose we define a symbol in one module, and want to use it in another some notation, such as.EXTERNAL, is used to tell assembler that a symbol is defined in another module linker will search symbol tables of other modules to resolve symbols and complete code generation before loading