Experiment 1 - Coal
Experiment 1 - Coal
Objective
• Introduction of Emu8086
• understand how programs are written in Emu8086 using Assembly Language
Time Required : 3 hrs
Programming Language : Assembly Language
Software Required : EMU 8086
Hardware Required : NIL
Introduction
Emu8086 is a program that compiles the source code (assembly language) and executes it.
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, 8086 machine code is fully compatible with all
next generations of Intel's microprocessors.
Downloading
Where to start?
• Start Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.
• Select "Samples" from "File" menu.
• Click [Compile and Emulate] button (or press F5 hot key).
• Click [Single Step] button (or press F8 hot key) and watch how the code is being
executed.
• Try opening other samples, all samples are heavily commented, so it's a great learning
tool.
Directives
ORG 100h is a compiler directive (it tells compiler how to handle the source code). This
directive is very important when you work with variables. It says to 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.
Why executable file is loaded at offset of 100h? Operating system keeps some data about
the program in the first 256 bytes of the CS (code segment), such as command line
parameters etc. Offset is used to get the offset address of the variable in register specified.
MOV instruction
• Copies the second operand (source) to the first operand (destination).
• The source operand can be an immediate value, general-purpose register or memory
location.
• The destination register can be a general-purpose register, or memory location. Both
operands must be the same size, which can be a byte or a word.
Syntax:
mov destination, source
Example:
mov ax, 10 ; puts the value of 10 in the register ax mov
cx, ax ; puts the value contained in the register ax into
cx
Register is a series of memory cells inside the CPU itself. Because registers are inside the
CPU there is very little overhead in working with them. There are four general purpose
registers, AX, BX, CX, and DX. These are the registers you will be using often. Each of
these general registers is 16- bit. They also have 8-bit counterparts. AX is 16 bits where as
AH and AL is 8bit. Note: - AH being the high bit, and AL being the low bit. Together AH
and AL make AX.
Procedure is a part of code that can be called from your program in order to make some
specific task. Procedures make program more structural and easier to understand.
Generally procedure returns to the same point from where it was called.
Web Resources
http://www.svu.edu.eg/specialunits/acadeet/dwnldFiles/trainMater/provis/emu86_short.pdf
Videos Resources
www.youtube.com/watch?v=pcyvLYb5XDc www.youtube.com/watch?
v=SqcVG6CA4J4
EXERCISES
Exercise 1.1
Load all example of assembly language one by one in Emu8086 and execute them.
Practice all these examples and analyses output.