Microprocessor Lab1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

8086 Microprocessors Lab 1

Lab one: Writing assembly programs in 8086 MP


1. Lab Objectives
In this lab we will learn how to use
 Assembly Language Tools and Familiarization with Emu8086 environment
 8086 Emulator to write assembly programs and running them
 Emulator to understand the step by the step execution of a program, and observe the memory
and register contents during and after execution
2. Introduction to the lab

Emu8086 combines an advanced source editor, assembler, disassemble and software emulator
(Virtual PC) with debugger. 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. This makes 8086 code very portable, since it runs both on ancient and on the modern computer
systems. Another advantage of 8086 instruction set is that it is much smaller, and thus easier to
learn.

2.1 Defining Variables

Variable is a memory location. For a programmer it is much easier to have some value be kept in
a variable named "var1" then at the address 5A73:235B, especially when you have 10 or more
variables. Our compiler supports two types of variables: BYTE and WORD.

Syntax for a variable declaration:


name DB value
name DW value
DB- is for Define Byte. DW - is for Define Word.
name - can be any letter or digit combination, and should start with a letter.
value - can be any numeric value in any supported numbering system, "?" symbol for variables
that are not initialized.
When compiler makes machine code, it automatically replaces all variable names with their offsets. In
memory list first row is an offset, second row is a hexadecimal value, third row is decimal value, and

1 of 3 | P a g e
8086 Microprocessors Lab 1

last row is an ASCII character value. Compiler is not case sensitive, so "VAR1" and "var1" refer to
the same variable.
2.2 Compiler directive: ORG 100h

It tells compiler that the executable file will be loaded at the offset of 100h (256 bytes), so compiler
should calculate the correct address for all variables when it replaces the variable names with their
offsets. Directives are never converted to any real machine code.

3. Procedures for writing and executing an assembly program


1. Install emu8086 4.08 and open it
2. Click new on the emulator, then chose .COM code template
3. Write your code on the given editor
4. Click [Compile and Emulate] button (or press F5 hot key).
5. Click [Single Step] button (or press F8 hot key), and watch how the code is being executed.

4. Lab1 Part one:


4.1 Executing Assembly Basic instructions, and Examining Register and memory
contents
a. Follow the above procedures and open the editor and write the code in Example 1 below.
b. Compile it. Then execute step by step.
c. Observe how the register and memory contents are affected.
d. Try to modify the register values by double clicking on their values and observe the
effects
Example 1:
ORG 100hv; directive required for a COM program.
MOV AX, 0B800h ; set AX to hexadecimal value of B800h.
MOV DS, AX ; copy value of AX to DS.
MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h.
MOV CH, 01011111b ; set CH to binary value.
MOV BX, 15Eh ; set BX to 15Eh.
MOV [BX], CX ; copy contents of CX to memory at B800:015E
RET; returns to operating system.
5. Lab1 Part Two: Exercises
Write assembly codes for the following problems and then assemble and execute them
1. Write a program that exchanges two values stored in two consecutive memory locations
using the mov instruction.
2. Write a program that exchanges two values stored in two consecutive memory locations
using the xchg instruction.
3. Write a program that loads effective address to the source index register
4. Write a program that loads an accumulator and data/extra segment registers using single
Instruction

2 of 3 | P a g e
8086 Microprocessors Lab 1

5. Write an 8086 assembly program that clears the value stored in CX using XOR
6. Write a program to mask bits D3D2D1D0 and to set bits D5D4 and to invert bits D7D6
of the AX register.
7. Write a program that adds two words in memory locations and stores the result in
subsequent memory location.
8. Write a program in 8086 microprocessors to multiply two 8-bit numbers, where numbers
are stored from offset 500 and store the result into offset 600
9. Write a program to execute the following statement CL=(2*AL+BL)/Dl.
10. Write a program that set Carry, Overflow, Direction and Trap flags, clear parity, sign and
zero flags, and invert Interrupt and Auxiliary carry flags of the flag register. Don’t use set
and clear instructions.
11. Write a program in 8086 microprocessor to find out the subtraction of corresponding
elements of two arrays of 8-bit n numbers, where size “n” is stored at offset 500 and the
numbers of first array are stored from offset 501 and the numbers of second array are
stored from offset 601 and store the result numbers into first array i.e offset 501
12. Write a program that counts up from 0 to 99 in BCD. Store the ODD numbers starting at
4100H.

N.B: You have to submit a lab report through E-learning in groups of three students.

3 of 3 | P a g e

You might also like