CS2422 Assembly Language & System Programming December 26, 2006.

Slides:



Advertisements
Similar presentations
1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Advertisements

1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Chapter 3 Loaders and Linkers
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida.
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.
Loaders and Linkers Object Program contains the information:
Chapter 3 System Software
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University.
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.
1 Chapter 1 Background Professor Gwan-Hwan Hwang Dept. Computer Science and Information Engineering National Taiwan Normal University 9/17/2009.
System Software.
Chapter 6: Machine dependent Assembler Features
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
Assembler – Machine Dependent Features
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
Loader- Machine Dependent Loader Features
CS2422 Assembly Language & System Programming December 7, 2006.
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.
CS2422 Assembly Language & System Programming December 14, 2006.
UNIT II ASSEMBLERS.
Today’s Topic Assembler: Basic Functions
A Simple Two-Pass Assembler
Assemblers.
CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.
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.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent.
Loader and Linker.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
UNIT III LOADERS AND LINKERS. This Unit gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Feature Loader.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
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 10 –Linkers.
ADHIPARASAKTHI ENGINEERING COLLEGE
김길용 교수 분산처리연구실 시스템 프로그래밍 김길용 교수 분산처리연구실
Machine dependent Assembler Features
CC410: System Programming
System Programming and administration
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Machine Independent Features
Simplified Instructional Computer (SIC)
Loaders and Linkers.
Chapter 1 Background Professor Gwan-Hwan Hwang
Simplified Instructional Computer (SIC)
A Simple Two-Pass Assembler
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Welcome to Systems Software
Loaders and Linkers.
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

CS2422 Assembly Language & System Programming December 26, 2006

Today’s Topics 3.1 Basic Loader Functions –Design of an Absolute Loader –A Simple Bootstrap Loader 3.2 Machine-Dependent Loader Features –Relocation –Program Linking

Introduction To execute an object program, we needs –Relocation, which modifies the object program so that it can be loaded at an address different from the location originally specified –Linking, which combines two or more separate object programs and supplies the information needed to allow references between them –Loading and Allocation, which allocates memory location and brings the object program into memory for execution

Overview of Chapter 3 Type of loaders –Assemble-and-go loader –Absolute loader (bootstrap loader) –Relocating loader (relative loader) –Direct linking loader Design options –Linkage editors –Dynamic linking –Bootstrap loaders

Assemble-and-go Loader Characteristic –The object code is stored in memory after assembly –Single JUMP instruction Advantage –Simple, developing environment Disadvantage –Whenever the assembly program is to be executed, it has to be assembled again –Programs have to be coded in the same language

Design of an Absolute Loader Absolute Program –Advantage Simple and efficient –Disadvantage The need for programmer to specify the actual address Difficult to use subroutine libraries Program Logic

Fig. 3.2 Algorithm for an absolute loader begin read Header record verify program name and length read first Text record while record type <> ’E’ do begin {if object code is in character form, convert into internal representation} move object code to specified location in memory read next object program record end jump to address specified in End record end

Loading of an absolute program (1/2) Fig. 3.1(a)

Loading of an absolute program (2/2) Fig. 3.1(b)

Object Code Representation Fig. 3.1(a) –Each byte of assembled code is given using its hexadecimal representation in character form –Easy to read by human beings In general –Each byte of object code is stored as a single byte –Most machine store object programs in a binary form –We must be sure that our file and device conventions do not cause some of the program bytes to be interpreted as control characters

A Simple Bootstrap Loader Bootstrap Loader –When a computer is first tuned on or restarted, a special type of absolute loader, called bootstrap loader is executed –This bootstrap loads the first program to be run by the computer -- usually an operating system Example (SIC bootstrap loader) –The bootstrap itself begins at address 0 –It loads the OS starting address 0x80 –No header record or control information, the object code is consecutive bytes of memory

Bootstrap loader for SIC/XE Begin X=0x80 (the address of the next memory location to be loaded) Loop A  GETC ( and convert it from the ASCII character code to the value of the hexadecimal digit ) save the value in the high-order 4 bits of S A  GETC combine the value to form one byte A  (A+S) store the value (in A) to the address in register X X  X+1 End GETCA  read one character if A=0x04 then jump to 0x80 if A<48 then GETC A  A-48 (0x30) if A<10 then return A  A-7 return

Fig. 3.3 Bootstrap loader for SIC/XE

Relocating Loaders Motivation –Efficient sharing of the machine with larger memory and when several independent programs are to be run together –Support the use of subroutine libraries efficiently Two methods for specifying relocation –Modification record (Fig. 3.4, 3.5) –Relocation bit (Fig. 3.6, 3.7) Each instruction is associated with one relocation bit These relocation bits in a Text record is gathered into bit masks

Modification Record For complex machines Also called RLD specification –Relocation and Linkage Directory Modification record col 1: M col 2-7: relocation address col 8-9: length (halfbyte) col 10: flag (+/-) col 11-17: segment name

Fig. 3.4: An SIC/XE Example (from Fig. 2.6) LineLoc Source statementObject code 50000COPY START FIRST STL RETADR17202D LDB #LENGTH69202D 13 BASE LENGTH CLOOP+JSUB RDREC4B A LDA LENGTH D COMP# JEQ ENDFIL JSUB WRREC4B10105D J CLOOP3F2FEC 45001AENDFIL LDA EOF D STA BUFFER0F LDA# STA LENGTH0F200D JSUB WRREC4B10105D 70002A 80002DEOF BYTE C’EOF’454F RETADR RESW LENGTH RESW BUFFER RESB 4096

115.READ RECORD INTO BUFFER RDREC CLEAR XB CLEAR AB A CLEAR SB C+LDT# RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB COMPR A,SA B JEQ EXIT E STCH BUFFER,X57C TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH RSUB4F CINPUT BYTE X’F1’F WRITE RECORD FROM BUFFER DWRREC CLEAR XB F LDT LENGTH WLOOP TD OUTPUTE JEQ WLOOP332FFA LDCH BUFFER,X53C B WD OUTPUTDF E TIXR TB850...(omitted)

Fig. 3.5

Relocation Bit For simple machines Relocation bit –0: No modification is necessary –1: Modification is needed Twelve-bit mask is used in each Text record –Since each text record contains less than 12 words –Unused words are set to 0 –Any value that is to be modified during relocation must coincide with one of these 3-byte segments e.g. line 210 Text record col 1: T col 2-7: starting address col 8-9: length (byte) col 10-12: relocation bits col 13-72: object code

Figure 3.6: Relocatable Program for SIC LineLoc Source statementObject code 50000COPYSTART FIRSTSTLRETADR CLOOPJSUBRDREC LDALENGTH COMPZERO CJEQENDFIL FJSUBWRREC JCLOOP3C ENDFILLDAEOF00002A STABUFFER0C BLDATHREE00002D 60001ESTALENGTH0C JSUBWRREC LDLRETADR RSUB4C AEOFBYTEC’EOF’454F DTHREEWORD ZEROWORD RETADRRESW LENGTHRESW BUFFERRESB4096

SUBROUTINE TO READ RECORD INTO BUFFER RDRECLDXZERO CLDAZERO FRLOOPTDINPUTE0105D JEQRLOOP30103D RDINPUT D8105D COMPZERO BJEQEXIT ESTCHBUFFER,X TIXMAXLEN2C105E JLTRLOOP38103F EXITSTXLENGTH ARSUB4C DINPUTBYTEX’F1’F EMAXLENWORD SUBROUTINE TO WRITE RECORD FROM BUFFER WRRECLDXZERO WLOOPTDOUTPUTE JEQWLOOP ALDCHBUFFER,X DWDOUTPUTDC TIXLENGTH2C JLTWLOOP RSUB4C OUTPUTBYTEX’05’05 255ENDFIRST

Fig. 3.7

Program Linking Goal –Resolve the problems with EXTREF and EXTDEF from different control sections (sec 2.3.5) Example –Program in Fig. 3.8 and object code in Fig. 3.9 –Use modification records for both relocation and linking Address constant External reference

Fig

Fig

Fig

Fig

Fig

Fig

Program Linking Example Fig Load address for control sections –PROGA –PROGB F –PROGC0040E251 Load address for symbols –LISTA: PROGA+0040=4040 –LISTB: PROGB+0060=40C3 –LISTC: PROGC+0030=4112 REF4 in PROGA –ENDA-LISTA+LISTC= =4126 –T F000014FFFFF600003F000014FFFFC0 –M LISTC

Fig. 3.10(a)

Fig. 3.10(b)