CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University.

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
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.
1 System Programming System Software, pp Chia-Hui Chang, Assistant Professor Dept. of Computer Science & Information Engineering National Central.
Simplified Instructional Computer (SIC). SIC Architecture Two versions: SIC and SIC/XE (extra equipments). SIC program can be executed on SIC/XE. Memory.
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.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
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.
CS2422 Assembly Language & System Programming December 26, 2006.
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
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.
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 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.
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
Machine Independent Assembler Features
Loaders and Linkers.
Machine Independent Assembler Features
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University

1 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

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

3 Design of an Absolute Loader Absolute program  Advantage Simple and efficient  Disadvantage Need for programmer to specify the actual address Difficult to use subroutine libraries  Program logic

4 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 Figure 3.2

5 Loading Absolute Program (1/2) H COPY A T E T 00101E 15 0C C F T E E0205D 30203F D8205D … T C C0000 F E … T C E Figure 3.1(a) (same as Fig. 2.3)

6 Loading Absolute Program (2/2)

7 Object Code Representation  In our object code file, Fig. 3.1(a) Each byte of assembled code is in the character form using its hexadecimal representation Easy to read by human beings  In general Most machines store object programs in a binary form; each byte of object code is stored as a single byte

8 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 Bootstrap loader loads the first program to be run by the computer -- usually an operating system  Example (SIC bootstrap loader) The bootstrap loader begins at address 0 It loads the OS starting at address 0x80 No header record or control information, the object code is consecutive bytes of memory

9 Bootstrap Loader for SIC/XE Begin X=0x80 (address of next memory location to be loaded) Loop A  GETC (convert it from ASCII to 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

10 Bootstrap Loader for SIC/XE BOOTSTART 0 BOOTSTRAP LOADER FOR SIC/XE CLEAR A CLEAR REGISTER A TO ZERO LDX #128 INITIALIZE REGISTER X TO HEX 80 LOOPJSUB GETC READ HEX FROM PROG BEING LOADED RMO A,S SAVE IN REGISTER S SHIFTL S,4 MOVE TO HIGM-ORDER 4 BITS JSUB GETC GET NEXT HEX DIGIT ADDR S,A COMBINE DIGITS TO FORM ONE BYTE STCH 0,X STORE AT ADDRESS IN REGISTER X TIXR X ADD 1 TO MEMORY ADDR LOADED J LOOP LOOP UNTIL END OF INPUT REACHED Figure 3.3

11 Bootstrap Loader for SIC/XE. SUBR TO READ ONE CHARACTER FROM INPUT DEVICE. GETCTD INPUT TEST INPUT DEVICE JEQ GETC LOOP UNTIL READY RD INPUT READ CHARACTER COMP #4 IF CHARACTER IS x04 (END FILE) JEQ 80 JUMP TO START OF LOADED PROG COMP #48 COMPARE TO HEX 30 (CHARACTER '0') JLT GETC SKIP CHARACTERS LESS THAN '0’ SUB #48 SUBTRACT HEX 30 FROM ASCII CODE COMP #10 IF RESULT < 10, CONVERSION DONE; JLT RETURN OTHERWISE, SUBTRACT 7 MORE SUB #7 (FOR HEX DIGITS 'A' THROUGH 'F‘) RETURN RSUB RETURN TO CALLER INPUT BYTE X'Fl’ CODE FOR INPUT DEVICE ENDLOOP

12 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

13 Relocating Loaders  Motivation Efficient sharing of memory for machines with larger memory and when several independent programs are to be run together Support 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 ‒ Relocation bits in a Text record is turned into bit masks

14 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

15 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 Figure 3.4

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 DWRREC CLEAR XB F LDT LENGTH WLOOP TD OUTPUTE JEQ WLOOP332FFA LDCH BUFFER,X53C B WD OUTPUTDF E TIXR TB850...(omitted)

17 Modification Record Figure 3.5

18 Relocation Bit  For simple machines  Relocation bit 0: No modification 1: Modification needed  Twelve-bit mask is used in each Text record Since each text record contains < 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

19 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 Figure 3.6 (from Figure 2.2)

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

21 Relocation by Bit Mask H COPY A T E FEC T 00001E 15 E00 0C C F … T E FFC E0105D 30103F D8105D … T C C0000 F T FE E DC1079 2C0036 … E Figure 3.7

22 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

23 Figure Loc Source statement Object code 0000 PROGA START 0 EXTDEF LISTA,ENDA EXTREF LISTB,ENDB,LISTC,ENDC 0020 REF1 LDA LISTA 03201D 0023 REF2 +LDT LISTB REF3 LDX #ENDA-LISTA LISTA EQU * ENDA EQU * 0054 REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 FFFFF6 005A PEF6 WORD ENDC-LISTC+LISTA F 005D REP7 WORD ENDA-LISTA-(ENDB-LISTB) REF8 WORD LISTB-LISTA FFFFC0 END REF1

24 Figure 3.9-1

25 Figure Loc Source statement Object code 0000 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA,ENDA,LISTC,ENDC REF1 +LDA LISTA A REF2 LDT LISTB D REF3 +LDX #ENDA-LISTA LISTB EQU * ENDB EQU * 0070 REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC-10 FFFFF REF6 WORD ENDC-LISTC+LISTA-1 FFFFFF 0079 REF7 WORD ENDA-LISTA-(ENDB-LISTB) FFFFF0 007C REF8 WORD LISTB-LISTA END

26 Figure 3.9-2

27 Figure Loc Source statement Object code 0000 PROG START 0 EXTDEF LISTC,ENDC EXTREF LISTA,ENDA,LISTB,ENDB REF1 +LDA LISTA C REF2 +LDT LISTB REF3 +LDX #ENDA-LISTA LISTC EQU * ENDC EQU * 0042 REF4 WORD ENDA-LISTA+LISTC REF5 WORD ENDC-LISTC REF6 WORD ENDC-LISTC+LISTA B REF7 WORD ENDA-LISTA-(ENDB-LISTB) E REF8 WORD LISTB-LISTA END

28 Figure 3.9-3

29 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

30 Figure 3.10(a)

31 Figure 3.10(b)