Assembly Language Lab2

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

EXPERIMENT 2 – INTRODUCTION TO EMU 8086

OBJECTIVE
In this lab, an introduction of Emu8086 will be given. Also, the Hello World Program will be explained to
make students understand how programs are written in Emu8086 using Assembly Language.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
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.
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.

11 Experiment 2 – Introduction to EMU 8086


SYNTAX:
MOV Destination, Source

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 whereas 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.
Syntax:
namePROC
; here goes the code
; of the procedure ...
RET
nameENDP
ACTIVITY 2.1 : HELLO WORLD PROGRAM
; Title Hello World Program
org 100h
.data ; Declare variables
hello_message db 'Hello','World',0dh,0ah,'$'
.code ; Write code
main proc
mov ax,@data ; Copy the address of data
mov ds,ax ; Segment into DS register
mov dx,offset hello_message
mov ah,9 ; MS-Dos Function to display string
INT 21H
mov ax,4C00h ; Halt the program and return control to OS
INT 21H
main endp
end main ; Mark the end of the source file

12 Experiment 2 – Introduction to EMU 8086


EXERCISE 2.1 [3]
Write the output (print and paste), of Activity 2.1 here: -

EXERCISE 2.2 [3]


Print your name and date of birth using the program in Activity 2.1. Paste outcome here.

13 Experiment 2 – Introduction to EMU 8086


EXERCISE 2.3 [4]
Load all example of assembly language one by one in Emu8086 and execute them. Practice all these examples
and analyses output. Paste outcomes here.

RESOURCES:
Download: https://download.cnet.com/Emu8086-Microprocessor-Emulator/3000-2069_4-10392690.html
https://www.youtube.com/watch?v=vlSjuq5BoG0
https://www.tutorialspoint.com/assembly_programming/assembly_introduction.htm

14 Experiment 2 – Introduction to EMU 8086

You might also like