34
Assembly Language Programming Appendix C

Assembly Language Programming - University of …€¦ · A Small Assembly Language Program Figure C-1. (a) An assembly language program. (b) The corresponding tracer display

Embed Size (px)

Citation preview

Assembly Language Programming

Appendix C

A Small Assembly Language Program

Figure C-1. (a) An assembly language program. (b) The corresponding tracer display.

The Processor Cycle

Steps for the execution of a single instruction:

• Fetch instruction from memory from code segment using PC.• Increment program counter.• Decode fetched instruction.

• Fetch necessary data from memory and/or CPU registers

• Perform instruction.• Store results of the instruction in memory and/or registers.• Go back to step 1 to start next instruction.

8088 Registers (1)

Figure C-2. The 8088 registers.

8088 Registers (2)

Figure C-2. The 8088 registers.

Flag or Condition Register

Bits set by arithmetic instructions and relate to result:

Z - result is zero

V - result generated an overflow

C - result generated a carry

A - Auxilary carry (out of bit 3)

Memory Organization and Segments

Four segments (chunks of memory) used by 8088

• The code segment.

• The data segment.

• The stack segment.• The extra segment.

Addressing (1)

Figure C-3. Operand addressing modes. The symbol # indicates a numerical value or label.

Addressing (2)

Figure C-3. Operand addressing modes. The symbol # indicates a numerical value or label.

8088 Instruction Set (1)

Figure C-4. Some of the most important 8088 instructions.

8088 Instruction Set (2)

Figure C-4. Some of the most important 8088 instructions.

8088 Instruction Set (3)

Figure C-4. Some of the most important 8088 instructions.

8088 Instruction Set (4)

Figure C-5. Conditional jumps.

8088 Instruction Set (5)

Figure C-6. An example stack.

8088 Instruction Set (6)

Figure C-7. Some UNIX system calls and subroutines in the interpreter.

The ACK-Based Assembler, as88 (1)

Figure C-8. The as88 pseudoinstructions.

The ACK-Based Assembler, as88 (2)

Figure C-9. Some of the escapes allowed by as88.

The Tracer (1)

Figure C-10. The tracer’s windows.

The Tracer (2)

For each project we can have up to 6 files:

pr.s for the assembly source code.

pr.$ for the composite source file.

pr.88 for the load file.

pr.i for preset standard input.

pr.t for preset tracer commands.

pr.# for linking the assembly code to the load file.

Tracer Commands (1)

Figure C-11. Tracer commands. Each command must be followed by carriage return (the Enter key). Empty box indicates just

carriage return needed. Commands with no Address field listed above have no address. # symbol represents integer offset.

Tracer Commands (2)

Figure C-11. Tracer commands. Each command must be followed by carriage return (the Enter key). Empty box indicates just

carriage return needed. Commands with no Address field listed above have no address. # symbol represents integer offset.

Hello World Example

Figure C-12. (a) HlloWrld.s. (b) The corresponding tracer window.

General Registers Example

Figure C-13. (a) Part of a program. (b) The tracer register window after line 7 has been executed. (c) The registers.

Call Command and Pointer Registers (1)

Figure C-14. The program vecprod.s.

Call Command and Pointer Registers (2)

Figure C-14. The program vecprod.s.

Call Command and Pointer Registers (3)

Figure C-15. Execution of vecprod.s when it reaches line 28 for the first time.

Call Command and Pointer Registers (4)

Figure C-16. The program arrayprt before debugging.

String Manipulation, String Instructions (1)

Figure C-17. (a) Copy a string (strngcpy.s).

String Manipulation, String Instructions (2)

Figure C-17. (b) Print a string backward (reverspr.s).

Dispatch Tables (1)

Figure C-18. A program demonstrating a multiway branch using a dispatch table.

Dispatch Tables (2)

Figure C-18. A program demonstrating a multiway branch using a dispatch table.

Buffered and Random File Access (1)

Figure C-19. A program with buffered read and random file access.

Buffered and Random File Access (2)

Figure C-19. A program with buffered read and random file access.

End

Appendix C