Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.

Slides:



Advertisements
Similar presentations
The Assembly Language Level
Advertisements

Chapter 3 Loaders and Linkers
Chapter 3 Loaders and Linkers
Machine Independent Assembler Features
The assembler is the system program that translate source code written in assembly language to object code( Machine Language) and other information for.
System Software Chih-Shun Hsu
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
Machine-Dependent Assembler Features (SIC/XE Assembler) Instruction Formats, Addressing Modes, and Program Relocation.
System Software by Leland L. Beck chapter 1, pp.1-20.
Assembler design.
Chapter 6: Machine dependent Assembler Features
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler I.
Chih-Hung Wang Chapter 2: Assembler (Full) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,
System Software by Leland L. Beck Chapter 2
Assembler – Assembler Design Options. One-Pass Assemblers (1/2) Main problem  Forward references Data items Labels on instructions Solution  Data items:
Chapter 2 Assemblers Assembler Linker Source Program Object Code
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
An introduction to systems programming
CS2422 Assembly Language & System Programming November 30, 2006.
Chih-Hung Wang Chapter 1: Background (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Assembler (Basic Functions)
Assembler – Machine Independent Features. Literals Design idea  Let programmers to be able to write the value of a constant operand as a part of the.
UNIT II ASSEMBLERS.
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
First part System Utilities Lecture 3 ASSEMBLER Ştefan Stăncescu 1.
Chapter 4 System Programming and Operating Systems -DM Dhamdhere
What is System Software? -a program that manages and supports the computer resources - manages operations of a computer system while it executes various.
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
CPS4200 System Programming 2007 Spring 1 Systems Programming Chapter 2 Assembler II.
CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software by Leland L. Beck Chapter 2.
CS2422 Assembly Language and System Programming Assembler Design Options Department of Computer Science National Tsing Hua University.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
Machine-Independent Assembler Features Literals, Symbol-Defining Statements, Expressions, Program Blocks, Control Sections and Program Linking.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers System Software by Leland L. Beck Chapter 2.
Assemblers Two functions: – Mnemonic opcode  Machine Code – Symbolic labels  machine addresses (in memory) Some features: – Depend on assembly language.
Assembler Design Options One-Pass and Multi-Pass Assemblers.
Assemblers System Software.
COMPILERS CLASS IV Er. Vikram Dhiman M.tech NIT jalandhar.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
CPS4200 System Programming Spring 1 Systems Programming Chapter 1 Background I.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
ADHIPARASAKTHI ENGINEERING COLLEGE
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
CC410: System Programming
Machine dependent Assembler Features
CC410: System Programming
System Programming and administration
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Chapter 9 : Assembler Design Options
Assembler Design Options
Assemblers - 2 CSCI/CMPE 3334 David Egle.
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Chapter 1 Computer architecture Languages: machine, assembly, high
Chapter 6 Programming the basic computer
Machine Independent Assembler Features
An introduction to systems programming
Presentation transcript:

Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,

Role of Assembler Source Program Assembler Object Code Loader Executable Code Linker 2

Chapter 2 -- Outline  Basic Assembler Functions  Machine-dependent Assembler Features  Machine-independent Assembler Features  Assembler Design Options 3

Introduction to Assemblers  Fundamental functions  Translating mnemonic operation codes to their machine language equivalents  Assigning machine addresses to symbolic labels  Machine dependency  Different machine instruction formats and codes 4

Example Program (Fig. 2.1)  Purpose  Reads records from input device (code F1)  Copies them to output device (code 05)  At the end of the file, writes EOF on the output device, then RSUB to the operating system  Program (See Fig. 2.1) 5

SIC Assembly Program (Fig. 2.1) Line numbers (for reference) Address labels Mnemonic opcode operands comments 6

SIC Assembly Program (Fig. 2.1) Index addressing Indicate comment lines 7

SIC Assembly Program (Fig. 2.1) 8

Example Program (Fig. 2.1)  Data transfer (RD, WD)  a buffer is used to store record  buffering is necessary for different I/O rates  the end of each record is marked with a null character (00 16 )  the end of the file is indicated by a zero-length record  Subroutines (JSUB, RSUB)  RDREC, WRREC  save link register first before nested jump 9

Assembler Directives  Pseudo-Instructions  Not translated into machine instructions  Providing information to the assembler  Basic assembler directives  START :  Specify name and starting address for the program  END :  Indicate the end of the source program, and (optionally) the first executable instruction in the program.  BYTE :  Generate character or hexadecimal constant, occupying as many bytes as needed to represent the constant.  WORD :  Generate one-word integer constant  RESB :  Reserve the indicated number of bytes for a data area  RESW :  Reserve the indicated number of words for a data area 10

Object Program  Header Col. 1H Col. 2~7Program name Col. 8~13Starting address (hex) Col Length of object program in bytes (hex)  Text Col.1 T Col.2~7Starting address in this record (hex) Col. 8~9Length of object code in this record in bytes (hex) Col. 10~69Object code ( )/6=10 instructions  End Col.1E Col.2~7Address of first executable instruction (hex) (END program_name) 11

Fig. 2.3 (Object Program) : Storage reserved by the loader

Assembler Tasks  The translation of source program to object code requires us the accomplish the following functions:  Convert mnemonic operation codes to their machine language equivalents (e.g. translate STL to 14 - Line 10)  Convert symbolic operands to their equivalent machine addresses format (e.g. translate RETARD to Line 10)  Build machine instructions in the proper format  Convert the data constants specified in the source program into their internal machine representations (e.g. translate EOF to 454F46) - Line 80  Write object program and the assembly listing 13

Example of Instruction Assemble  Forward reference STCH BUFFER,X (54) 16 1 (001) 2 (039)

Forward Reference  A reference to a label (RETADR) that is defined later in the program  Solution  Two passes  First pass: does little more than scan the source program for label definition and assign addresses (such as those in the Loc column in Fig. 2.2).  Second pass: performs most of the actual instruction translation previously defined. 15

Difficulties: Forward Reference  Forward reference: reference to a label that is defined later in the program. LocLabelOperatorOperand 1000FIRSTSTLRETADR 1003CLOOPJSUBRDREC … ………… 1012JCLOOP … ………… 1033RETADRRESW1 16

Two Pass SIC Assembler  Pass 1 (define symbols)  Assign addresses to all statements in the program  Save the addresses assigned to all labels for use in Pass 2  Perform assembler directives, including those for address assignment, such as BYTE and RESW  Pass 2 (assemble instructions and generate object program)  Assemble instructions (generate opcode and look up addresses)  Generate data values defined by BYTE, WORD  Perform processing of assembler directives not done during Pass 1  Write the object program and the assembly listing 17

Two Pass SIC Assembler  Read from input line  LABEL, OPCODE, OPERAND Pass 1Pass 2 Intermediate file Object codes Source program OPTAB SYMTAB 18

Assembler Data Structures  Operation Code Table (OPTAB)  Symbol Table (SYMTAB)  Location Counter (LOCCTR) Source Object Program Intermediate file Pass 1 Pass 2 OPTAB SYMTAB LOCCTR 19

Location Counter ( LOCCTR)  A variable that is used to help in the assignment of addresses, i.e., LOCCTR gives the address of the associated label.  LOCCTR is initialized to be the beginning address specified in the START statement.  After each source statement is processed during pass 1, the length of assembled instruction or data area to be generated is added to LOCCTR. 20

Operation Code Table ( OPTAB)  Contents:  Mnemonic operation codes (as the keys)  Machine language equivalents  Instruction format and length  Note: SIC/XE has instructions of different lengths  During pass 1:  Validate operation codes  Find the instruction length to increase LOCCTR  During pass 2:  Determine the instruction format  Translate the operation codes to their machine language equivalents  Implementation: a static hash table (entries are not normally added to or deleted from it)  Hash table organization is particularly appropriate 21

SYMTAB  Contents:  Label name  Label address  Flags (to indicate error conditions)  Data type or length  During pass 1:  Store label name and assigned address (from LOCCTR) in SYMTAB  During pass 2:  Symbols used as operands are looked up in SYMTAB  Implementation:  a dynamic hash table for efficient insertion and retrieval  Should perform well with non-random keys (LOOP1, LOOP2). COPY1000 FIRST 1000 CLOOP1003 ENDFIL1015 EOF1024 THREE102D ZERO1030 RETADR1033 LENGTH1036 BUFFER1039 RDREC

Fig. 2.2 (1) Program with Object code 23

Fig. 2.2 (2) Program with Object code 24

Fig. 2.2 (3) Program with Object code 25

Figure 2.1 (Pseudo code Pass 1) 26

Figure 2.1 (Pseudo code Pass 1) 27

Figure 2.1 (Pseudo code Pass 2) 28

Figure 2.1 (Pseudo code Pass 2) 29