CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University.

Slides:



Advertisements
Similar presentations
Loader. Role of Loader Source Program Translator Object Program Loader Object program ready for execution Memory Translator – Assembler/Compiler.
Advertisements

Machine Independent Assembler Features
System Software Chih-Shun Hsu
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.
System Software.
Chapter 6: Machine dependent Assembler Features
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
Chih-Hung Wang Chapter 2: Assembler (Full) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley,
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
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.
Assembler – Machine Dependent Features
1 Chapter 2 Assemblers Source Program Assembler Object Code Loader.
CS2422 Assembly Language and System Programming Machine Dependent Assembler Features Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming December 7, 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.
Machine-Independent Assembler Features
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.
A Simple Two-Pass Assembler
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.
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.
Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent.
1 Assemblers System Software by Leland L. Beck Chapter 2.
Machine Independent Assembler Features
G.Umamaheswari Lect/IT R.M.D.EC system software
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.
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
System Programming System Software:
Machine dependent Assembler Features
CC410: System Programming
Machine Independent Assembler Features
System Programming and administration
System Software by Leland L. Beck Chapter 2
SYSTEM SOFTWARE - UNIT II
Machine Independent Assembler Features
Assembler Design Options
Assembler Design Options
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Optional Assembler Features
Assembler Design Options
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
Machine Independent Assembler Features
Machine Independent Assembler Features
Presentation transcript:

CS2422 Assembly Language and System Programming Machine Independent Assembler Features Department of Computer Science National Tsing Hua University

1 Today ’ s Topic  Section 2.3 of Beck ’ s “ System Software ” book -- Machine Independent Assembler Features Literals Symbol Defining Statements Expressions Program Blocks Control Sections and Program Linking

2 Literals  Design idea Let programmers write the value of a constant operand as a part of the instruction that uses it Avoid having to define the constant elsewhere in the program and make up a label for it  Example (Fig. 2.10) A ENDFIL LDA =C’EOF’ WLOOPTD =X’05’

3 (Figure 2.9) 50000COPY START FIRST STL RETADR17202D LDB #LENGTH69202D 14 BASE LENGTH CLOOP+JSUB RDREC4B A LDA LENGTH D COMP# JEQ ENDFIL JSUB WRREC4B10105D J CLOOP3F2FEC 45001AENDFIL LDA=C’EOF’ D STA BUFFER0F LDA# STA LENGTH0F200D JSUB WRREC4B10105D 70002A 93 LTORG RETADR RESW LENGTH RESW BUFFER RESB BUFEND EQU * MAXLEN EQU BUFEND - BUFFER

4 115.READ RECORD INTO BUFFER RDREC CLEAR XB CLEAR AB A CLEAR SB C+LDT #MAXLEN RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB COMPR A,SA B JEQ EXIT E STCH BUFFER,X 57C TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH RSUB4F CINPUT BYTE X’F1’F1

WRITE RECORD FROM BUFFER DWRREC CLEAR X B F LDT LENGTH WLOOP TD =X’05’ E JEQ WLOOP 332FFA LDCH BUFFER,X 53C B WD =X’05’ DF E TIXR T B JLT WLOOP 3B2FEF RSUB 4F END FIRST

6 Literals vs. Immediate Operands  Immediate operands Operand value is assembled as part of the machine instruction LDA#  Literals The assembler generates the specified value as a constant at some other memory location 45001AENDFILLDA=C’EOF’  Compare (Fig. 2.6) 45001AENDFILLDAEOF DEOFBYTEC’EOF’454F46

7 Literal - Implementation (1/3)  Literal pools Normally literals are placed into a pool at the end of the program ‒ See Fig (END statement) In some cases, it is desirable to place literals into a pool at some other location in object program ‒ Use assembler directive LTORG: create a literal pool that contains all of the literal operands used since the previous LTROG, and place it where LTORG was encountered ‒ Reason: keep literal operand close to the instruction

8 (Figure 2.10) 50000COPY START FIRST STL RETADR17202D LDB #LENGTH69202D 14 BASE LENGTH CLOOP+JSUB RDREC4B A LDA LENGTH D COMP# JEQ ENDFIL JSUB WRREC4B10105D J CLOOP3F2FEC 45001AENDFIL LDA=C’EOF’ D STA BUFFER0F LDA# STA LENGTH0F200D JSUB WRREC4B10105D 70002A 93 LTORG 002D*=C’EOF’454F RETADR RESW LENGTH RESW BUFFER RESB BUFEND EQU * MAXLEN EQU BUFEND - BUFFER

9 115.READ RECORD INTO BUFFER RDREC CLEAR XB CLEAR AB A CLEAR SB C+LDT #MAXLEN RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB COMPR A,SA B JEQ EXIT E STCH BUFFER,X 57C TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH RSUB4F CINPUT BYTE X’F1’F1

WRITE RECORD FROM BUFFER DWRREC CLEAR X B F LDT LENGTH WLOOP TD =X’05’ E JEQ WLOOP 332FFA LDCH BUFFER,X 53C B WD =X’05’ DF E TIXR T B JLT WLOOP 3B2FEF RSUB 4F END FIRST 1076* =X’05’ 05

11 Literal - Implementation (2/3)  Duplicate literals WLOOPTD=X’05’ BWD=X’05’  Assembler should recognize duplicate literals and store only one copy of specified data value By comparing defining character string, e.g. =X’05’ By comparing the generated data value, e.g. =C’EOF’ and =X’454F46’, but benefits are usually not great enough to justify the additional complexity in the assembler

12 Literal - Implementation (3/3)  Use LITTAB: Literal name, operand value & length, operand address  Pass 1 Build LITTAB with literal name, operand value/length When LTORG is encountered, assign address to each literal not yet assigned an address, update LOCCTR  Pass 2 Search LITTAB for each literal encountered and generate the operand address Data values of literals in literal pool are generated similarly as using BYTE or WORD statements Generate modification record for literals that represent an address in the program

13 Today ’ s Topic  Section 2.3 of Beck ’ s “ System Software ” book -- Machine Independent Assembler Features Literals Symbol Defining Statements Expressions Program Blocks Control Sections and Program Linking

14 Symbol-Defining Statements (1/2)  Users can define labels on instructions or data areas The value of a label is the address assigned to the statement  Users can also define symbols with values symbolEQUvalue value can be constants, other symbols, expressions Making source program easier to understand No forward reference

15 Symbol-Defining Statements (2/2)  Example 1: MAXLEN EQU LDT#MAXLEN  Example 2: BASEEQUR1 COUNTEQUR2 INDEXEQU R3  Example 3: MAXLENEQUBUFEND-BUFFER +LDT#4096

16 Today ’ s Topic  Section 2.3 of Beck ’ s “ System Software ” book -- Machine Independent Assembler Features Literals Symbol Defining Statements Expressions Program Blocks Control Sections and Program Linking

17 Expressions (1/2)  Expressions are evaluated by assembler to produce a single operand address or value  Absolute or relative expressions MAXLENEQUBUFEND-BUFFER BUFEND and BUFFER are relative terms, representing addresses relative to program beginning  change with program start address But, BUFEND  BUFFER has absolute value ‒ When relative terms are paired with opposite signs, the dependency on starting address is canceled out; the result is an absolute value

18 Expressions (2/2)  No relative terms may enter into a multiplication or division operation; the followings are errors: BUFEND+BUFFER, 100-BUFFER, 3*BUFFER  Assembler needs to track type of an expression, to generate Modification records if needed Can add one flag in SYMTAB

19 Today ’ s Topic  Section 2.3 of Beck ’ s “ System Software ” book -- Machine Independent Assembler Features Literals Symbol Defining Statements Expressions Program Blocks Control Sections and Program Linking

20 Program Blocks  Program blocks Refer to segments of code that are rearranged within a single object program unit USE [blockname] Assembler will rearrange these segments to put together all source lines belonging to a block At the beginning, statements are assumed to be part of the unnamed (default) block ‒ If no USE statements are included, the entire program belongs to this single block

21 Line Source statement COPY START FIRST STL RETADR17202D CLOOP JSUB RDREC4B LDA LENGTH COMP# C 0 JEQ ENDFIL F 0 JSUB WRREC4B203B J CLOOP3F2FEE ENDFIL LDA=C’EOF’ STA BUFFER0F B 0 LDA# E 0 STA LENGTH0F JSUB WRREC4B USE CDATA RETADR RESW LENGTH RESW USE CBLKS BUFFER RESB BUFEND EQU * MAXLEN EQU BUFEND - BUFFER (Figure 2.11) 3 blocks: Default (0) CDATA (1) CBLKS (2)

READ RECORD INTO BUFFER USE RDREC CLEAR XB CLEAR AB B 0 CLEAR SB D 0 +LDT#MAXLEN RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB A 0 COMPR A,SA C 0 JEQ EXIT F 0 STCH BUFFER,X 57A02F TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH13201F A 0 RSUB4F USE CDATA INPUT BYTE X’F1’F1

WRITE RECORD FROM BUFFER D 0 USE D 0WRREC CLEAR X B F 0 LDT LENGTH WLOOP TD=X’05’ E3201B JEQ WLOOP 332FFA LDCH BUFFER,X 53A B 0 WD=X’05’ DF E 0 TIXR T B JLT WLOOP 3B2FEF RSUB 4F USE CDATA 253 LTORG * =C’EOF’ 454F46 000A 1* =X’05’ END FIRST

24 Program Blocks - Implementation  Pass 1 Each program block has a separate location counter Each label is assigned an address that is relative to the start of the block that contains it At end of Pass 1, last value of the location counter for each block indicates the length of that block The assembler can then assign to each block a starting address in the object program  Pass 2 The address of each symbol can be computed by adding the assigned block starting address and the relative address of the symbol to that block

25 LineLoc/Block Source statement Object code COPY START FIRST STL RETADR17202D CLOOP JSUB RDREC4B LDA LENGTH COMP# C 0 JEQ ENDFIL F 0 JSUB WRREC4B203B J CLOOP3F2FEE ENDFIL LDA=C’EOF’ STA BUFFER0F B 0 LDA# E 0 STA LENGTH0F JSUB WRREC4B USE CDATA RETADR RESW LENGTH RESW USE CBLKS BUFFER RESB BUFEND EQU * MAXLEN EQU BUFEND - BUFFER (Figure 2.12)

READ RECORD INTO BUFFER USE RDREC CLEAR XB CLEAR AB B 0 CLEAR SB D 0 +LDT#MAXLEN RLOOP TD INPUTE JEQ RLOOP332FFA RD INPUT DB A 0 COMPR A,SA C 0 JEQ EXIT F 0 STCH BUFFER,X 57A02F TIXR TB JLT RLOOP3B2FEA EXIT STX LENGTH13201F A 0 RSUB4F USE CDATA INPUT BYTE X’F1’F1

WRITE RECORD FROM BUFFER D 0 USE D 0WRREC CLEAR X B F 0 LDT LENGTH WLOOP TD=X’05’ E3201B JEQ WLOOP 332FFA LDCH BUFFER,X 53A B 0 WD=X’05’ DF E 0 TIXR T B JLT WLOOP 3B2FEF RSUB 4F USE CDATA 253 LTORG * =C’EOF’ 454F46 000A 1* =X’05’ END FIRST

28 Figure 2.12  Each source line is given a relative address and a block number  Absolute symbol has no block number (line 107) LDALENGTH LENGTH = (Block 1) = = 0069 LOCCTR = (Block 0) = 0009 Displacement = 0069 – 0009 = 060

29 Program Readability  Program readability No extended format instructions (lines 15, 35, 65) No need for base relative addressing (line 13, 14) LTORG is used to make sure the literals are placed ahead of any large data areas (line 253)  Object code It is not necessary to physically rearrange the generated code in the object program; loader can handle it See Fig. 2.13, Fig. 2.14

30 Figure 2.13 H COPY T E B B203B... T 00001E 09 0F2048 4B2029 3E203F T D B410 B400 B E FFA … T B2FEA 13201F 4F0000 T 00006C 01 F1 T 00004D 19 B E3201B 332FFA 53A016 DF2012 … T 00006D F46 05 E CDATA

31 Figure 2.14

32 Today ’ s Topic  Section 2.3 of Beck ’ s “ System Software ” book -- Machine Independent Assembler Features Literals Symbol Defining Statements Expressions Program Blocks Control Sections and Program Linking

33 Control Sections & Code Linking  Control sections Most often used for subroutines or other logical subdivisions of a program Programmer can assemble, manipulate, and load each of these control sections separately Instructions in one control section may need to refer to instructions or data in another section Thus, there should be some means for linking control sections together Fig. 2.15, 2.16: three control sections (COPY, RDREC, WRREC)

COPY START 0 6 EXTDEF BUFFER,BUFEND,LENGTH 7 EXTREF RDREC,WRREC FIRST STL RETADR CLOOP+JSUB RDREC4B LDA LENGTH A COMP# D JEQ ENDFIL JSUB WRREC4B J CLOOP3F2FEC ENDFIL LDA=C’EOF’ A STA BUFFER0F D LDA# STA LENGTH0F200A JSUB WRREC4B ARETADR RESW DLENGTH RESW LTORG 0030*=C’EOF’454F BUFFER RESB BUFEND EQU * MAXLEN EQU BUFEND - BUFFER (Figure 2.16)

RDREC CSECT 115.READ RECORD INTO BUFFER EXTREF BUFFER,LENGTH,BUFEND CLEAR XB CLEAR AB CLEAR SB LDT MAXLEN77201F RLOOP TD INPUTE3201B C JEQ RLOOP332FFA F RD INPUT DB COMPR A,SA JEQ EXIT STCH BUFFER,X B TIXR TB D JLT RLOOP3B2FE EXIT+STX LENGTH RSUB4F INPUT BYTE X’F1’F MAXLEN WORD BUFEND – BUFFER

WRREC CSECT WRITE RECORD FROM BUFFER EXTREF LENGTH,BUFFER CLEAR X B LDT LENGTH WLOOP TD =X’05’ E JEQ WLOOP 332FFA C +LDCH BUFFER,X WD =X’05’ DF TIXR T B JLT WLOOP 3B2FEF RSUB 4F END FIRST 001B* =X’05’ 05

37 External Definition & References  External definition EXTDEF name [, name] Declare symbols that are defined in this control section and used by other sections  External reference EXTREF name [,name] Declare symbols that are used in this control section and are defined elsewhere  For EXTREF labels, assembler has no idea where the corresponding control section will be loaded  use CLOOP +JSUB RDREC 4B STCH BUFFER,X MAXLEN WORD BUFEND-BUFFER

38 Implementation  Assembler must include information in object program that will cause loader to insert proper values where required  Define record Col. 1D Col. 2-7Name of external symbol defined in this control section Col Relative address within this control section (hex) Col Repeat info in Col for other external symbols  Refer record Col. 1R Col. 2-7Name of external symbol referred to in this section Col Name of other external reference symbols

39 Modification Record  Modification record Col. 1M Col. 2-7Starting address of the field to be modified (hex) Col. 8-9Length of the field to be modified, in half-bytes (hex) Col External symbol whose value is to be added to or subtracted from the indicated field Note: control section name is automatically an external symbol, i.e. it is available for use in Modification records.  Example Figure 2.17 M RDREC M COPY

40 Figure 2.17 (1/2) H COPY D BUFFER BUFEND LENGTH 00002D R RDREC WRREC T D B B T 00001D 0D F200A 4B E2000 T F46 M RDREC M WRREC M WRREC E

41 H RDREC B R BUFFER LENGTH BUFEND T D B410 B400 B F E3201B 332FFA DB T 00001D 0E 3B2FE F0000 F M BUFFER M LENGTH M BUFEND M BUFFER E H WRREC C R LENGTH BUFFER T C B E FFA DF M LENGTH M 00000D 05+BUFFER E Figure 2.17 (2/2) 190 MAXLEN WORD BUFEND - BUFFER

42 External Reference in Expression  Earlier definitions Required all of the relative terms be paired in an expression (an absolute expression), or that all except one be paired (a relative expression)  New restriction Both terms in each pair must be relative within the same control section Ex: BUFEND-BUFFER Ex: RDREC-COPY  In general, assembler cannot determine whether or not the expression is legal at assembly time. This work will be handled by a linking loader.