ECE2046 – Computer Organization and Architecture

LAB: CO2 Duration: 3 hours

Study of CPU using a Simulator

1. Objective

To observe and examine the 8086 arithmetic, logical and program flow instructions set using the Emu8086 simulator.

2. Software

Emu8086 simulator.

3. Introduction

Emu8086 is an emulator of 8086 microprocessor (Intel and AMD compatible) with integrated 8086 assembler and tutorials for beginners. The emulator runs programs like the real microprocessor in a step-by-step mode. It shows the contents of registers, memory, stack, variables and flags. All memory values can be investigated and edited easily. In addition, the instructions can be executed in a regular forward direction and also in reverse direction.

Emu8086’s visual interface is very easy to work with. You can watch registers, flags and memory values while your program executes. It also provides views on Arithmetic & Logical Unit (ALU) that show the internal work of the central processor unit (CPU).

The emulator runs programs on a Virtual PC. This completely blocks your program from accessing real hardware, such as hard-drives and memory. Since your assembly code runs on a virtual machine, this makes debugging much easier.

8086 machine code is fully compatible with Intel's micro-processors, including Pentium II and Pentium 4. This makes 8086 code very portable, since it runs both on old and on the modern computer systems. Another advantage of 8086 instruction set is that it is much smaller, and thus easier to learn.

Emu8086 has a much easier syntax than any of the major assemblers, but will still generate a program that can be executed on any computer that runs 8086 machine code.

[Note: If you don't use Emu8086 to compile the code, you won't be able to step through your actual source code while running it.]


4. General Procedures

1.  Execute Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.

2.  Select code examples from "File" -> "Examples". All examples are heavily commented, so it’s a great learning tool.

3.  To run the code example in the emulator, click [emulate] button (or press F5).

4.  Click [single step] button (or press F8) to step through the code one instruction at a time, observing changes in registers and the emulator screen. Click [step back] button (or press F6) to see what happens when reversing those changes.

5. Exercises

Exercise 1: Quick study of the simulator operations

1.  Click on the icon of Emu8086 to start the simulator. When the simulator starts, you should see the starting message “Loading” as shown in Figure 1.

Figure 1: Emu8086 Loading Page

2.  After the initial screen is displayed, you should click on the [quick start tutor] option to start 8086 assembler tutorials. A screen as shown in Figure 2 will appear. Read all the tutorials. Pay more attention to these three sections:

part 6: arithmetic and logic instructions

part 7: program flow control

part 9: the stack

3. After reading and understanding the 8086 assembler and its operations, you are required to describe the above three sections using your own words in your lab report.

Figure 2: Emu8086 Tutorials

Exercise 2: Load first program and analyse the operations

1.  Click on the “file” menu and then on “open”. Select “MySource” directory and choose “MMU.asm” file. (You can download the file from ECE2046 course content in MMLS to your local harddisk drive)

2.  “MMU.asm” source code will be displayed in the window.

3.  Run the code by clicking the [emulate] button. This will open the “emulated source code” window and a window showing registers, memory, [single step] and [run] buttons.

4.  Click on [single step] button. Observe and record all the changes taking place every time you click this button. Examine the contents of registers and comprehend their effects in the source code window. After the program is executed completely, an “emulator screen” window will be displayed as shown in Figure 3. It shows the results of the program.

5.  Based on your analysis in the previous step, deduce the reasons of the changes taking place in the registers. Include all your observations and descriptions in your lab report.

Figure 3: Emulator Screen

Exercise 3: Traffic lights program

1.  Select the “traffic lights” program from "file" -> "examples".

2.  Understand the program by observing the program flow and interpreting the instructions in the source code.

3.  Run the code by clicking the [emulate] button. This will open the “emulated source code” window and a window showing registers, memory, [single step] and [run] buttons.

4.  Click on the [single step] button. Observe and record the changes taking place every time you click this button. Examine the contents of registers and their effects in the source code window. After the first OUT instruction is executed, a window showing the simulation of traffic lights will be displayed as shown in Figure 4.

5.  Based on your analysis in the previous step, deduce the reasons of the changes taking place in the registers. Include all your observations and descriptions in your lab report.

Figure 4: Traffic lights window

Exercise 4: Add/Subtract program

1.  Select the “add/substract” program from "file" -> "examples".

2.  Understand the program by observing the program flow and interpreting the instructions in the source code.

3.  Run the code by clicking the [emulate] button. This will open the “emulated source code” window and a window showing registers, memory, [single step] and [run] buttons.

4.  Click on the [single step] button. Observe and record the changes taking place every time you click this button. Examine the contents of registers and their effects in the source code window.

5.  Based on your analysis in the previous step, deduce the reasons of the changes taking place in the registers. Include all your observations and descriptions in your lab report.

6

Exercise 5: Arithmetic program

By now you should have acquired all the necessary knowledge to design your own program. Thus, in this exercise you are required to construct your own program to perform arithmetic operations based on the last four digit of your student ID.

Assume that the last four digits of your student ID are abcd. You are required to perform the following arithmetic operation:

2 * (ab10 + cd10) * (510 + ab10) – 510

Your final answer should be stored in the AX register.

1.  Click on “com template” from “file” -> “new”.

2.  Edit your source code in the template.

3.  Emulate the program and single-step the code. Observe and record the contents of the registers each time after single-stepping. Deduce the reasons of the changes taking place in the registers. Include all your observations and descriptions in your lab report.

4.  Calculate the answer for the arithmetic operations using a calculator and validate the final answer with the content of the AX register. Include this in your lab report.

6