Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CS2422 Assembly Language and System Programming Loader Department of Computer Science National Tsing Hua University."— Presentation transcript:

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

2 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

3 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

4 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

5 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

6 5 Loading Absolute Program (1/2) H COPY 001000 00107A T 001000 1E 141033 482039 001036 281030 301015 482061... T 00101E 15 0C1036 482061 081044 4C0000 454F46 000003 000000 T 002039 1E 041030 001030 E0205D 30203F D8205D 281030 … T 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064 … T 002073 07 382064 4C0000 05 E 001000 Figure 3.1(a) (same as Fig. 2.3)

7 6 Loading Absolute Program (2/2)

8 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

9 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

10 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

11 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

12 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

13 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

14 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

15 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

16 15 An SIC/XE Example (from Fig. 2.6) LineLoc Source statementObject code 50000COPY START 0 100000FIRST STL RETADR17202D 120003 LDB #LENGTH69202D 13 BASE LENGTH 150006CLOOP+JSUB RDREC4B101036 20000A LDA LENGTH032026 25000D COMP#0290000 300010 JEQ ENDFIL332007 350013+JSUB WRREC4B10105D 400017 J CLOOP3F2FEC 45001AENDFIL LDA EOF032010 50001D STA BUFFER0F2016 550020 LDA#3010003 600023 STA LENGTH0F200D 650026+JSUB WRREC4B10105D 70002A J@RETADR3E2003 80002DEOF BYTE C’EOF’454F46 950030RETADR RESW 1 1000033LENGTH RESW 1 1050036BUFFER RESB 4096 Figure 3.4

17 16 1251036RDREC CLEAR XB410 1301038 CLEAR AB400 132103A CLEAR SB440 133103C+LDT#409675101000 1351040RLOOP TD INPUTE32019 1401043 JEQ RLOOP332FFA 1451046 RD INPUT DB2013 1501049 COMPR A,SA004 155104B JEQ EXIT332008 160104E STCH BUFFER,X57C003 1651051 TIXR TB850 1701053 JLT RLOOP3B2FEA 1751056EXIT STX LENGTH134000 1801059 RSUB4F0000 185105CINPUT BYTE X’F1’F1 210105DWRREC CLEAR XB410 212105F LDT LENGTH774000 2151062WLOOP TD OUTPUTE32011 2201065 JEQ WLOOP332FFA 2251068 LDCH BUFFER,X53C003 230106B WD OUTPUTDF2008 235106E TIXR TB850...(omitted)

18 17 Modification Record Figure 3.5

19 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

20 19 Relocatable Program for SIC LineLoc Source statementObject code 50000COPYSTART0 100000FIRSTSTLRETADR140033 150003CLOOPJSUBRDREC481039 200006LDALENGTH000036 250009COMPZERO280030 30000CJEQENDFIL300015 35000FJSUBWRREC481061 400012JCLOOP3C0003 450015ENDFILLDAEOF00002A 500018STABUFFER0C0039 55001BLDATHREE00002D 60001ESTALENGTH0C0036 650021JSUBWRREC481061 700024LDLRETADR080033 750027RSUB4C0000 80002AEOFBYTEC’EOF’454F46 85002DTHREEWORD3000003 900030ZEROWORD0000000 950033RETADRRESW1 1000036LENGTHRESW1 1050039BUFFERRESB4096 Figure 3.6 (from Figure 2.2)

21 20 1251039RDRECLDXZERO040030 130103CLDAZERO000030 135103FRLOOPTDINPUTE0105D 1401042JEQRLOOP30103D 1451045RDINPUT D8105D 1501048COMPZERO280030 155104BJEQEXIT301057 160104ESTCHBUFFER,X548039 1651051TIXMAXLEN2C105E 1701054JLTRLOOP38103F 1751057EXITSTXLENGTH100036 180105ARSUB4C0000 185105DINPUTBYTEX’F1’F1 190105EMAXLENWORD4096001000 2101061WRRECLDXZERO040030 2151064WLOOPTDOUTPUTE01079 2201067JEQWLOOP301064 225106ALDCHBUFFER,X508039 230106DWDOUTPUTDC1079 2351070TIXLENGTH2C0036 2401073JLTWLOOP381064 2451076RSUB4C0000 2501079OUTPUTBYTEX’05’05 255ENDFIRST

22 21 Relocation by Bit Mask H COPY 000000 00107A T 000000 1E FEC 140033 481039 000036 280030 300015 481061... T 00001E 15 E00 0C0036 481061 080044 4C0000 454F46 000003 … T 001039 1E FFC 040030 000030 E0105D 30103F D8105D … T 001057 1C 800 100036 4C0000 F1 001000 T 001061 19 FE0 040030 E01079 301064 508039 DC1079 2C0036 … E 000000 Figure 3.7

23 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

24 23 Figure 3.8-1 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+4 77100004 0027 REF3 LDX #ENDA-LISTA 050014... 0040 LISTA EQU *... 0054 ENDA EQU * 0054 REF4 WORD ENDA-LISTA+LISTC 000014 0057 REF5 WORD ENDC-LISTC-10 FFFFF6 005A PEF6 WORD ENDC-LISTC+LISTA-1 00003F 005D REP7 WORD ENDA-LISTA-(ENDB-LISTB) 000014 0060 REF8 WORD LISTB-LISTA FFFFC0 END REF1

25 24 Figure 3.9-1

26 25 Figure 3.8-2 Loc Source statement Object code 0000 PROGB START 0 EXTDEF LISTB,ENDB EXTREF LISTA,ENDA,LISTC,ENDC... 0036 REF1 +LDA LISTA 03100000 003A REF2 LDT LISTB+4 772027 003D REF3 +LDX #ENDA-LISTA 05100000... 0060 LISTB EQU *... 0070 ENDB EQU * 0070 REF4 WORD ENDA-LISTA+LISTC 000000 0073 REF5 WORD ENDC-LISTC-10 FFFFF6 0076 REF6 WORD ENDC-LISTC+LISTA-1 FFFFFF 0079 REF7 WORD ENDA-LISTA-(ENDB-LISTB) FFFFF0 007C REF8 WORD LISTB-LISTA 000060 END

27 26 Figure 3.9-2

28 27 Figure 3.8-3 Loc Source statement Object code 0000 PROG START 0 EXTDEF LISTC,ENDC EXTREF LISTA,ENDA,LISTB,ENDB... 0018 REF1 +LDA LISTA 03100000 001C REF2 +LDT LISTB+4 77100004 0020 REF3 +LDX #ENDA-LISTA 05100000... 0030 LISTC EQU *... 0042 ENDC EQU * 0042 REF4 WORD ENDA-LISTA+LISTC 000030 0045 REF5 WORD ENDC-LISTC-10 000008 0048 REF6 WORD ENDC-LISTC+LISTA-1 000011 004B REF7 WORD ENDA-LISTA-(ENDB-LISTB) 000000 004E REF8 WORD LISTB-LISTA 000000 END

29 28 Figure 3.9-3

30 29 Program Linking Example  Fig. 3.10  Load address for control sections PROGA00400063 PROGB0040637F PROGC0040E251  Load address for symbols LISTA: PROGA+0040=4040 LISTB: PROGB+0060=40C3 LISTC: PROGC+0030=4112  REF4 in PROGA ENDA-LISTA+LISTC=14+4112=4126 T0000540F000014FFFFF600003F000014FFFFC0 M00005406+LISTC

31 30 Figure 3.10(a)

32 31 Figure 3.10(b)


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

Similar presentations


Ads by Google