Presentation is loading. Please wait.

Presentation is loading. Please wait.

2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.

Similar presentations


Presentation on theme: "2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate."— Presentation transcript:

1 2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate mnemonic operation codes to machine language equivalents. Overview: r Basic Assembler Functions r Machine-Dependent Assembler Features r Machine-Independent Assembler Features r Assembler Design Options

2 2 : Assembler 2 r Assembler directives: m START : Specify name and starting address for the program m END : … m BYTE : Generate character or hexdecimal constant m WORD: Generate one-word integer constant m RESB : Reserve the indicated number of bytes for a data area m RESW : … Basic Assembler Functions (Using SIC as an Example)

3 2 : Assembler 3 Example of a SIC Assembler Language Program

4 2 : Assembler 4 Example of a SIC Assembler Language Program (cont.)

5 2 : Assembler 5 Example of a SIC Assembler Language Program (cont.)

6 2 : Assembler 6 A Simple SIC Assembler r The translation steps m Convert mnemonic operation codes to their machine language equivalent. m Convert symbolic operands to their equivalent machine addresses. m Build the machine instructions in the proper format. m Convert the data constants specified in the source program into their internal machine representations. m Write the object program and the assembly listing.

7 2 : Assembler 7 Output: the object program

8 2 : Assembler 8 The Object code for the above program

9 2 : Assembler 9 The Object code for the above program (cont.)

10 2 : Assembler 10 The Object code for the above program (cont.)

11 2 : Assembler 11 The Format for Object Program r The object program will later be loaded into memory for execution. r Three types of records for object program format m Header: contains the program name, starting address, and length. m Text: contains the translated instructions and data of the program m End: marks the end of the object program and specifies the address in the program where execution is to begin.

12 2 : Assembler 12 The Format for Object Program (cont.)

13 2 : Assembler 13 The object program

14 2 : Assembler 14 Two Passes of our Simple Assembler

15 2 : Assembler 15 The Data Structures r Two major data structures: r Operation code table (OPTAB) r Symbol table (SYMTAB) r Note: SYMTAB is usually organized as a hash table for efficiently of insertion and retrieval. r Location counter (LOCCTR)

16 2 : Assembler 16 The Algorithm (Pass 1)

17 2 : Assembler 17 The Algorithm (Pass 2)

18 2 : Assembler 18 Machine-Dependent Assembler Features (using SIC/XE as an example) r Addressing modes m Immediate addressing modes: COMP #0 m Indirect addressing: J @RETADR m The extended instruction format +LDT #4096 m Most of the register-to-memory instructions are assembled using either program-counter relative or base relative addressing. If either program-counter relative nor base relative addressing can be used, then the 4-byte (Format 4) must be used..

19 2 : Assembler 19 Example of a SIC/XE Assembler Language Program

20 2 : Assembler 20 Example of a SIC/XE Assembler Language Program (cont.)

21 2 : Assembler 21 Example of a SIC/XE Assembler Language Program (cont.)

22 2 : Assembler 22 Output: the object program

23 2 : Assembler 23 The Object code for the above program

24 2 : Assembler 24 The Object code for the above program (cont.)

25 2 : Assembler 25 The Object code for the above program (cont.)

26 2 : Assembler 26 Program Relocation r An object program that contains the information necessary to perform this kind of modification is called a relocatable program.

27 2 : Assembler 27 Program Relocation (cont.) r We can solve the relocation problem in the following way: r 1. When the assembler generates the object code for the JSUB instruction we are considering, it will insert the address of RDREC relative to the start of the program. (This is the reason we initialized the location counter to 0 for the assembly) r 2. The assembler will also produce a command for the loader, instructing it to add the beginning address of the program to the address field in the JSUB instruction at load time.

28 2 : Assembler 28 Program Relocation (cont.)

29 2 : Assembler 29 Program Relocation (cont.)

30 2 : Assembler 30 Machine-Independent Assembler Features r Literals r Symbol-Defining Statements r Expressions r Program Blocks r Control Sections and Program Linking

31 2 : Assembler 31 r It is often convenient for the programmer to be able to write the values of a constant operand as a part of the instruction that uses it. Such an operands is called a literal. r E.g., (In Fig 2.9) r 45 001A ENDFIL LDA =C’EOF’ 032010 r 215 1062 WLOOP TD =X’05’ E32011 r The difference between a literal and an immediate operand. With immediate addressing, the operand value is assembled as part of the machine instruction. With a literal, the assembler generate the specified value as a constant at some other memory location. Literal

32 2 : Assembler 32 r Literal pools: Normally literals are placed into a pool at the end of the program. The assembly listing of a program containing literals usually includes a listing of this literal pool, which shows the assigned addresses and the generated data values. r The assembler directive LTORG is used for creating the literal pool. Literal (cont.)

33 2 : Assembler 33 Program demonstrating additional assembler features

34 2 : Assembler 34 Program demonstrating additional assembler features (cont.)

35 2 : Assembler 35 Program demonstrating additional assembler features (cont.)

36 2 : Assembler 36 The above program with object code

37 2 : Assembler 37 The above program with object code (cont.)

38 2 : Assembler 38 The above program with object code (cont.)

39 2 : Assembler 39 Symbol-Defining Statements r Most assembler provides an assembler directive that allows the programmer to define symbols and specify their values. r The assembler directive : EQU r E.g., symbolEQUvalue r Usage sample: +LDT#4096 +LDT#MAXLEN MAXLENEQU4096

40 2 : Assembler 40 r STABRESB 1100 r SYMBOLEQUSTAB r VALUEEQUSTAB+6 r FLAGSEQUSTAB+9 r LDAVALUE,X Symbol-Defining Statements (An example…)

41 2 : Assembler 41 Expressions r Assembler generally allow arithmetic expressions formed according to the normal rules using the operators +, -, *, and / r E.g., MAXLENEQUBUFEND-BUFFER

42 2 : Assembler 42 Program Blocks r The source program logically contained subroutines, data areas, etc. However they were handled by the assembler as one entity, resulting in a single block of object code. r Note: The term program blocks refer to segments of code that are rearranged within a single object program unit, and control section to refer to segments that are translated into independent object program units. r The assembler directive USE indicates which portions of the source program belong to the various blocks.

43 2 : Assembler 43 Example of a program with multiple program blocks

44 2 : Assembler 44 Example of a program with multiple program blocks (cont.)

45 2 : Assembler 45 Example of a program with multiple program blocks (cont.)

46 2 : Assembler 46 The above program with object code

47 2 : Assembler 47 The above program with object code (cont.)

48 2 : Assembler 48 The above program with object code (cont.)

49 2 : Assembler 49 Program Blocks r Pass 1 Use separate location counter for each program block. r Pass 2 The assembler needs the address for each symbol relative to the start of the object program.

50 2 : Assembler 50 The object program

51 2 : Assembler 51 The loading processes

52 2 : Assembler 52 Control sections and program linking r A control section is a part of the program that maintain its identity after assembly; each such control section can be loaded and relocated independently of the others. r Note: 1. The assembler has no idea where any other control section will be loaded at execution time. 2. The reference between control sections are called external reference. r Two assembler directive: 1. EXTDEF: defined the external symbol that may be used by other sections. 2. EXTREF: named the symbols that are used in this control section and defined elsewhere.

53 2 : Assembler 53 Illustration of control sections and program linking

54 2 : Assembler 54 Illustration of control sections and program linking (cont.)

55 2 : Assembler 55 Illustration of control sections and program linking (cont.)

56 2 : Assembler 56 The above program with object code

57 2 : Assembler 57 The above program with object code (cont.)

58 2 : Assembler 58 The above program with object code (cont.)

59 2 : Assembler 59 Control sections and program linking (cont.) r The two new record types are Define and Refer.

60 2 : Assembler 60 The object program

61 2 : Assembler 61 Assembler Design Options – One-pass Assembler r Main problem: r One need to solve the forward reference problem. r Solution: r Require all such areas be defined in the source program before they are referenced. r In order to reduce the size of the problem, many one-pass assemblers prohibit forward reference to data items. r Usually one-pass assembler generate object code in memory for immediate execution. No object program is written out, and no loader is needed. --------- load-and-go assembler.

62 2 : Assembler 62 Assembler Design Options – One-pass Assembler (cont.) r If an instruction operand is a symbol that has not yet been defined, the operand address is omitted when the instruction is assembled. r The address of the operand field of the instruction that refers to the undefined symbol is added to a list of forward references associated with the symbol table entry. r When the definition for a symbol is encountered, the forward reference list for that symbol is scanned, and the proper address is inserted into any instructions previously generated.

63 2 : Assembler 63 Sample program for a one-pass assembler

64 2 : Assembler 64 Sample program for a one-pass assembler (cont.)

65 2 : Assembler 65 Sample program for a one-pass assembler (cont.)

66 2 : Assembler 66 Object code in memory and symbol table entries for above program (after scanning line 40)

67 2 : Assembler 67 Object code in memory and symbol table entries for above program (after scanning line 160)

68 2 : Assembler 68 Object program from one-pass assembler for above program

69 2 : Assembler 69 Assembler Design Options – Multi-pass Assembler

70 2 : Assembler 70 Example of multi-pass assembler operation

71 2 : Assembler 71 Example of multi-pass assembler operation (cont.)

72 2 : Assembler 72 Example of multi-pass assembler operation (cont.)

73 2 : Assembler 73 Example of multi-pass assembler operation (cont.)

74 2 : Assembler 74 Example of multi-pass assembler operation (cont.)


Download ppt "2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate."

Similar presentations


Ads by Google