ML 1
ML 1
ML 1
8086 Emulator
Experiment No.1
Microprocessor Laboratory
Third Stage
Morning Study
Group (B)
1.1 Introduction
This program is extremely helpful for those who just begin to study assembly
language. It compiles the source code and executes it on emulator step by step. Visual
interface is very easy to work with. You can watch registers, flags and memory while
your program executes.
Arithmetic & Logical Unit (ALU) shows the internal work of the central processor unit
(CPU). 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 all next generations of Intel's microprocessors, including
Pentium II and Pentium 4.
Despite the name of a register, it's the programmer who determines the usage
for each general-purpose register. The main purpose of a register is to keep a
number (variable). The size of the above registers is 16 bit, it's something like:
0011000000111001b (in binary form), or 12345 in decimal (human) form. 4
general purpose registers (AX, BX, CX, DX) are made of two separates 8-bit
registers, for example if AX= 0011000000111001b, then AH=00110000b and
AL=00111001b. Therefore, when you modify any of the 8-bit registers 16-bit
register is also updated, and vice-versa. the same is for other 3 registers, "H" is
for high and "L" is for low part. Because registers are located inside the CPU, they
are much faster than memory. Accessing a memory location requires the use of
a system bus, so it takes much longer. Accessing data in a register usually takes
no time. therefore, you should try to keep variables in the registers. register sets
are very small and most registers have special purposes which limit their use as
variables, but they are still an excellent place to store temporary data of
calculations.
Although it is possible to store any data in the segment registers, this is never a
good idea. the segment registers have a very special purpose - pointing at
accessible blocks of memory. Segment registers work together with general
purpose register to access any memory value. For example, if we would like to
access memory at the physical address 12345H (hexadecimal), we should set the
DS = 1230H and SI = 0045H. This is good, since this way we can access much more
memory than with a single register that is limited to 16-bit values. CPU makes a
calculation of physical address by multiplying the segment register by 10h and
adding general purpose register to it (1230h * 10H + 45H = 12345H):
➢ Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For
example, when you add bytes 255 + 1 (result is not in range 0...255). When
there is no overflow, this flag is set to 0.
➢ Zero Flag (ZF) - set to 1 when result is zero. For none zero result this flag is
set to 0.
➢ Sign Flag (SF) - set to 1 when result is negative. When result is positive it is
set to 0. Actually, this flag take the value of the most significant bit.
➢ Overflow Flag (OF) - set to 1 when there is a signed overflow. For example,
when you add bytes 100 + 50 (result is not in range -128...127).
➢ Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in
result, and to 0 when there is odd number of one bits. Even if result is a word
only 8 low bits are analyzed!
➢ Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low
nibble (4 bits).
➢ Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts
from external devices.
Microprocessor Laboratory Experiment No.1
➢ Direction Flag (DF) - this flag is used by some instructions to process data
chains, when this flag is set to 0 - the processing is done forward, when this
flag is set to 1 the processing is done backward.
Generally, you cannot access these registers directly.
By default, DS segment register is used for all modes except those with BP register, for
this SS segment register is used. There is an easy way to remember all those possible
combinations using this chart:
You can form all valid combinations by taking only one item from each column or
skipping the column by not taking anything from it. As you see BX and BP never go
together. SI and DI also don't go together. Here is an example of a valid addressing
mode: [BX+5]. The value in segment register (CS, DS, SS, ES) is called a "segment", and
the value in purpose register (BX, SI, DI, BP) is called an "offset". When DS contains
value 1234H and SI contains the value 7890H it can be also recorded as 1234:7890. The
physical address will be 1234H * 10H + 7890H = 19BD0H.
[Single Step] button executes instructions one by one stopping after each
instruction.
(Run] button executes instructions one by one with delay set by step delay
between instructions.
Double click on register text-boxes opens "Extended Viewer" window with value
of that register converted to all possible forms. You can modify the value of the
register directly in this window.
Double click on memory list item opens "Extended Viewer" with WORD value
loaded from memory list at selected location. Less significant byte is at lower
address: LOW BYTE is loaded from selected position and HIGH BYTE from next
memory address. You can modify the value of the memory word directly in the
"Extended Viewer" window, you can modify the values of registers on runtime
by typing over the existing values.
Microprocessor Laboratory Experiment No.1
MOV DS, 100 - is illegal instruction because segment registers cannot be set
directly, general purpose register should be used:
MOV AX, 100
MOV DS, AX
MOV AL, 300 - is illegal instruction because AL register has only 8 bits, and thus
maximum value for it is 255 (or 11111111b), and the minimum is 128.
Microprocessor Laboratory Experiment No.1
1.5 Procedure
For each of the following exercises:
1. Write down the following program in the text editor and make # COM file.
2. Compile & emulate the program to its Hex code.
3. Compare between the assembled and disassembled programs.
4. Write down the machine instructions (Hex code) of the program
5. Use the single step execution command to run the program.
6. Verify the contents of the registers used in each instruction used in this program
including the IP in each step of the execution.
1.6 Exercises
1. Execute the following program and write the value of AX,BX,CX.
MOV AX,552BH
MOV BX,8922
MOV CX,AX
HLT
❖ Solution:
AX value BX value CX value
Instruction IP value
AH AL BH BL CH CL
MOV AX,552BH 55 2B 00 00 00 00 0003
MOV BX,8922 55 2B 22 DA 00 00 0006
MOV CX,AX 55 2B 22 DA 55 2B 0008
➢ MOV AX,01011111
MOV CH,AX
MOV DX,80
MOV 200H,CX
HLT
❖ Solution:
1.7 Discussion
1. a) What is the function of an assembler and compiler?
❖ Assembler, it translates a medium-level or assembly language (what humans
could write in simple shape) to machine language (a pattern of bits that what
processor works), which means it allows the programmer to use mnemonic codes
such as ADD for addition in place of binary number such as 01000111.
2. What is the difference between the physical and the logical address?
3. Calculate the physical memory location for each of the following cases?
a- The logical address D470H in the extra segment.
b- The logical address 2D90H in the stack segment.
C- MOV [BP],AL if BP=2C30H.
Assume ES=52B9, SS=5D27, DS=E000, and CS=B3FF.
Microprocessor Laboratory Experiment No.1