the assembly language level - it.uom.gr€¦ · the assembly language level chapter 7. definitions...

38
The Assembly Language Level Chapter 7

Upload: vanthuan

Post on 18-Aug-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

The Assembly Language Level

Chapter 7

Page 2: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Definitions

• Translator– Converts user program to another language

• Source language– Language of original program

• Target language– Language into which source code is converted

– Object code or executable binary• Interpretation

– Source translated, immediately executed

Page 3: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Steps of Translation

1. Generation of equivalent program in target language

2. Execution of newly generated program– Happens only after Step 1 completed– Contrast to interpretation

Page 4: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Assembly Language

• One-to-one correspondence between machine instructions and statements in assembly program

• Provides better performance and access to the machine

• Statements can contain:

– Label field – Operation (opcode) field– Operand field

– Comments field

Page 5: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Format of an Assembly Language Statement (1)

Figure 7-1. Computation of N = I + J. (a) x86.

Page 6: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Format of an Assembly Language Statement (2)

Figure 7-1. Computation of N = I + J. (b) Motorola 680x0.

Page 7: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Format of an Assembly Language Statement (3)

Figure 7-1. Computation of N = I + J. (c) SPARC.

Page 8: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Pseudoinstructions (1)

Figure 7-2. Some of the pseudoinstructions available in the MASM assembler (MASM).

Page 9: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Pseudoinstructions (2)

Figure 7-2. Some of the pseudoinstructions available in the MASM assembler (MASM).

Page 10: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Macro Definition

Macro header giving name of macro being defined

Text – body of the macro

Pseudoinstruction marking end of definition

Page 11: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Macro Call, Expansion (1)

Figure 7-3. Assembly language code for interchanging P and Q twice. (a) Without a macro. (b) With a macro.

Page 12: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Macro Call, Expansion (2)

Figure 7-4. Comparison of macro calls with procedure calls.

Page 13: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Macros with Parameters

Figure 7-5. Nearly identical sequences of statements.(a) Without a macro. (b) With a macro.

Page 14: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Pass 1 of Two Pass Assembler

Figure 7-6. The instruction location counter (ILC) keeps track of the address where the instructions will be loaded in memory. In this example, the statements prior to MARIA occupy 100 bytes.

Page 15: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Tables Kept by Pass 1

• Symbol table

• Pseudoinstruction table • Opcode table • Literal table

Page 16: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Information Kept in Symbol Table

• Length of data field associated with symbol• Relocation bits• Is the symbol is accessible outside the procedure

Page 17: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Example Symbol Table

Figure 7-7. A symbol table for the program of Fig. 7-6.

Page 18: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Opcode Table

Figure 7-8. A few excerpts from the opcode table for an x86 assembler

Page 19: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Results of Pass One (1)

Figure 7-9. Pass one of a simple assembler.

Page 20: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Results of Pass One (2)

Figure 7-9. Pass one of a simple assembler.

Page 21: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Pass Two (1)

Figure 7-10. Pass two of a simple assembler

Page 22: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Pass Two (2)

Figure 7-10. Pass two of a simple assembler

Page 23: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Dealing with Typical Code Errors

Examples:

• A symbol has been used but not defined

• A symbol has been defined more than once

• The name in the opcode field is not a legal opcode• An opcode is not supplied with enough operands• An opcode is supplied with too many operands• An number contains an invalid character like 143G6

• Illegal register use (e.g., a branch to a register)

• The END statement is missing

Page 24: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

The Symbol Table (1)

Figure 7-11. Hash coding. (a) Symbols, values, and the hash codes derived from the symbols.

Page 25: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

The Symbol Table (2)

Figure 7-11. Hash coding. (b) Eight-entry hash table with linked lists of symbols and values.

Page 26: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Linking and Loading

Figure 7-12. Generation of an executable binary program from a collection of independently translated source procedures requires

using a linker.

Page 27: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Tasks Performed by the Linker (1)

Figure 7-13. Each module has its own address space, starting at 0.

Page 28: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Tasks Performed by the Linker (2)

• Constructs table of all object modules, lengths

• Assigns base address to each object module• Relocates all instructions that reference memory• Links instructions that reference other procedures

Page 29: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Tasks Performed by the Linker (3)

Figure 7-14. Object module table constructed in step 1 shown for the modules of Fig. 7-14. Gives name, length, and starting

address of each module.

Page 30: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Structure of an Object Module (2)

Figure 7-14. (a) object modules of Fig. 7-13 after being positioned in the binary image but before being relocated and linked.

Page 31: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Structure of an Object Module (3)

Figure 7-14. (b) The same object modules

after linking and after relocation has been performed.

Page 32: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Structure of an Object Module (1)

Figure 7-15. The internal structure of an object module produced by a translator. The Identification field comes first.

Page 33: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Binding Time and Dynamic Relocation (1)

Possibilities:

• When program is written

• When program is translated• When program is linked but before it is loaded• When program is loaded• When a base register used for addressing is loaded

• When instruction containing the address is executed

Page 34: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Binding Time and Dynamic Relocation (2)

Figure 7-16. The relocated binary program of Fig. 7-14(b) moved up 300 addresses. Many instructions now refer to an incorrect

memory address.

Page 35: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Dynamic Linking (1)

Figure 7-17. Dynamic linking. (a) Before EARTH is called.

Page 36: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Dynamic Linking (2)

Figure 7-17. Dynamic linking. (b) After EARTH

has been called and linked.

Page 37: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

Dynamic Linking (3)

Figure 7-18. Use of a DLL file by two processes.

Page 38: The Assembly Language Level - it.uom.gr€¦ · The Assembly Language Level Chapter 7. Definitions ... Pass 1 of Two Pass Assembler Figure 7-6. ... Pass Two (2) Figure 7-10. Pass

End

Chapter 7