You are on page 1of 29

Assembling, editing, linking, and executing Assembly code examples using Emu8086

Agenda
About Lab
Lab Policies
Weekly Lab Schedule

About Lab1
Part1 : Introduction to Emu8086
Some Terminology
Exercise : Numbering Systems

Part2 : Opt-in Example in Emu8086


Part 3: Assemble and execute instructions in Emu8086
Part 4: Writing and Running Assembly Code in Emu8086
Part 5: Exercise Part
Part 6: Conclusion Part
2

About Lab
Compulsory
2 Lab Hours/week
Lab Hours : Tuesday: 12:00 13:45,
Wednesday: 16:00 17:45

Announcements/etc via
http://kisi.gediz.edu.tr/akaratas/en/com353-mikroislemciler/

Res. Asst. Arzum Karata


arzum.karatas@gediz.edu.tr
Office : D-212

Office Hours :
On Mondays : up to lunch time
3

Lab Policies
Attendance: Attendance in the laboratory sessions is mandatory. For each
lab that you fail to attend without a valid excuse (such as a medical
report), you will receive the grade of 0.
Missing more than 2 of the labs will cause your overall grade for the lab
to be FF. Leaving early or coming late can be cause for giving the 0 grade,
and is considered missing that lab. Both partners in a lab group must stay
until the lab is completed and checked by the TA, or till the end of the lab
time, whichever comes first.
Makeup: Missing a lab for an excused reason will allow you to make up
that lab. Make-up opportunities will be either in the same week (at
another section's lab time), or during a free week in the middle of the
term, or at the end of the semester. Students who miss lab must therefore
contact us as soon as possible with the reason for the absence, so that
make up opportunities can be arranged.

Lab Policies(cont.)
Grading: You will be graded according to your preliminary report, your
final implementation of the lab that you demonstrate, your answers to
any questions that are asked during or at the end of the demo, and
your participation in the lab.

We will be very careful in grading the labs, homework


assignments, exams so that everybody gets the grade that
he/she deserves. Copying will not be tolerated and will be
checked and punished rigorously.
5

Weekly Lab Schedule(Tentative)

Lab-1 : Assembling, editing, linking, and executing


Assembly code examples using Emu8086
Time : 2 lab hours
Objective :
Learn
EMU8086 installation
EMU8086 environment

Learn how to:


Assemble instructions into the memory of 8086 using Emu8086
Use Emu8086 to execute instructions
Run opt-in programs in EMU8086
Write a complete assembly program.
Edit an existing source program.
7

Lab-1 : Assembling, editing, linking, and executing


Assembly code examples using Emu8086(cont)

Lab Outcomes :
Practice 8086 Emulator
Loading, verifying and saving machine code
Executing instructions and tracing programs

Part I: Introduction to Emu8086


Everything for learning assembly language in
one pack! Emu8086 combines a source editor,
assembler, disassembler, software emulator
(Virtual PC) with debugger
Visual interface is very easy to work with. You
can watch registers, flags and memory while
your program executes.
download the latest student version of EMU86
from the web page www.emu8086.com.
9

Some Terminology

Editor
Assembler
Linker
Debugger

10

Get Your Feet : Numbering System


Base Convertor :allows you to convert numbers
from any system and to any system. You can work
both with 8 bit and 16 bit values.
a)10100101b = ?
b) 1234h = ?
c) 39 = ? h

11

Get Your Feet : Numbering System


Expression Evaluator: can be used to make
calculations between numbers in different
systems and convert numbers from one
system to another
a) 0FFFFh *10h +0FFFFh

12

Part 2: Opt-in Examples in Emu8086


Procedure :
1- Start Emu8086 by selecting its icon from the start menu, or
by running Emu8086.exe.
2. Select "Examples" from "File" menu.
3. Click [Compile and Emulate] button (or press F5 hot key).
4. Click [Single Step] button (or press F8 hot key), and watch
how the code is being executed.
a) add/subtract
b) palindrome
c) traffic lights
d) led test
e) stepper motor
f) thermometer
13

Part 3: Assemble and execute


instructions in Emu8086
Step 1: Use emu8086 to assemble the instructions
(a) MOV AX,BX
(b) MOV AX,0AAAAh
(c) MOV AX,[BX]
(d) MOV AX,[4]
(e) MOV AX,[BX+SI]
(f) MOV AX,[SI+4]
(g) MOV AX,[BX+SI+4]
later ..
14

GENERAL PURPOSE
REGISTERS(Remainder)
8086 CPU has 8 general purpose registers, each register
has its own name:
AX - the accumulator register
BX - the base address register
CX - the count register
DX - the data register
SI - source index register.
DI - destination index register.
BP - base pointer.
SP - stack pointer.
Later ..
15

SEGMENT REGISTERS(Remainder)
CS - points at the segment containing the current program.
DS - generally points at segment where variables are
defined.
ES - extra segment register, it's up to a coder to define its
usage.
Later ..

16

SPECIAL PURPOSE
REGISTERS(Remainder)
IP - the instruction pointer.
Flags Register - determines the current state of the
processor.
IP register always works together with CS segment
register and it points to currently executing instruction.
Flags Register is modified automatically by CPU after
mathematical operations, this allows to determine the
type of the result, and to determine conditions to transfer
control to other parts of the program.
Generally you cannot access these registers directly.
Later ..
17

MOV Instruction
MOV dest, source
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 generalpurpose register, or memory location.
Both operands must be the same size, which can
be a byte or a word.
18

MOV Instruction (cont.)

19

Part 3: Assemble and execute


instructions in Emu8086
Step 2 : Initialize the internal registers of the 80x86
as follows:
(AX) = 0000H
(BX) = 0001H
(CX) = 0002H
(DX) = 0003H
Then , verify the initialization by displaying the new
content of register. Please put a check if you can
verify it.
20

Part 4: Writing and Running


Assembly Code in Emu8086
Hello World !

21

Part 5: Exercise Part


Exercise 1:
In this part, we will identify the x86 arithmetic
instructions and examine a program which will perform
the following arithmetic operations:
Calculate : (30 10 + 15 10 ) * ( 575 10 225 10 ) + 210

Procedure:
1. Choose New and specify COM template in
emu8086.
2. Enter the following cod to the editor:
22

Exercise-1 (cont.)

3. Start emulation by clicking the emulate


button on the toolbar. A new emulator window
will appear.
4. Single-step the program codes by pressing the
single step button on the toolbar of the
emulator window.
23

Exercise-1 (cont.)
5. Each time after pressing the single step button, check
and record down the contents of AX and BX registers in
Table 1

6. Using a calculator, calculate the answer for the above


arithmetic operations
Is it the same as the final answer in the AX register?

24

Exercise - 2

In this example, we will develop a program to perform the


following arithmetic operations:
12 10 * ( 20010 225 10 ) + 127
Procedure:
1. Develop an assembly language program to perform the
above arithmetic operations by only using registers AX and BX
(write the program in Table 1.2).
2. Write the program who does the calculation above into the
assembler editor in EMU8086
3. Emulate the program by pressing the emulate button on
the toolbar.
4. In the emulator window, single-step the program codes by
pressing the single step button on the toolbar.
25

Exercise - 2

: (cont.)

5. Each time after single-stepping, observe and


record down the contents of AX and BX registers
in Table 2.

26

Exercise - 2

: (cont.)

6. Using a calculator, calculate the answer for


the above arithmetic operations: ..
Is it the same as the final answer in the AX
register? .

27

Part 6: Conclusion
Please express what you learn with this
laboratory work with at most one paragraph.

28

Acknowledgement

Slides have been based in-part upon original notes of a


number of sheets and including:
Assembling, editing, linking, and executing assembly
language programs using Emu8086 and MASM ,
University of Jordan
TASM, EDIT, DEBUG and Emu8086 Assembler Tools,
Eastern Mediterranean University.
Advanced Microprocessors Lab Sheet, Multimedia
University, 2012

29

You might also like