0% found this document useful (0 votes)
19 views9 pages

Emulator Guide

Emu8086 is an emulator that allows running 8086 programs on modern computers. It includes an editor to write assembly code and debug programs by single stepping. The document provides examples of code, variables, arrays, interrupts and using included macros to simplify programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Emulator Guide

Emu8086 is an emulator that allows running 8086 programs on modern computers. It includes an editor to write assembly code and debug programs by single stepping. The document provides examples of code, variables, arrays, interrupts and using included macros to simplify programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Emu8086 is an emulator that allows us to run on modern computers those

programs developed for that processor. With this emulator, you can also code
in assembly language as it comes along with a built-in editor, which allows us
to recreate a totally realistic user experience on PCs equipped with this
processor.
Where to start?
1. Start Emu8086 by selecting its icon from the start menu, or by running
Emu8086.exe.
2. Select "Samples" 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.
5. Try opening other samples, all samples are heavily commented, so it's a
great learning tool.

Complete 8086 instruction set


CMPSB MOV

AAA CMPSW JAE JNBE JPO MOVSB RCR SCASB

AAD CWD JB JNC JS MOVSW REP SCASW

AAM DAA JBE JNE JZ MUL REPE SHL

AAS DAS JC JNG LAHF NEG REPNE SHR

ADC DEC JCXZ JNGE LDS NOP REPNZ STC

ADD DIV JE JNL LEA NOT REPZ STD

AND HLT JG JNLE LES OR RET STI

CALL IDIV JGE JNO LODSB OUT RETF STOSB

CBW IMUL JL JNP LODSW POP ROL STOSW

CLC IN JLE JNS LOOP POPA ROR SUB

CLD INC JMP JNZ LOOPE POPF SAHF TEST

CLI INT JNA JO LOOPNE PUSH SAL XCHG

CMC INTO JNAE JP LOOPNZ PUSHA SAR XLATB

CMP IRET JNB JPE LOOPZ PUSHF SBB XOR

JA RCL

Operand types:

➢ REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP,

SP.

➢ SREG: DS, ES, SS, and only as second operand: CS.

➢ memory: [BX], [BX+SI+7], variable, etc...(see Memory Access).


➢ immediate: 5, -24, 3Fh, 10001101b, etc...

Things to remember:
When two operands are required for an instruction they are separated by
comma. For example:

REG, memory

When there are two operands, both operands must have the same size (except
shift and rotate instructions). For example:

AL, DL
DX, AX
m1 DB ?
AL, m1
m2 DW ?
AX, m2

Some examples contain macros, so it is advisable to use Shift + F8 hot key to


Step Over (to make macro code execute at maximum speed set step delay to
zero), otherwise emulator will step through each instruction of a macro. Here is
an example that uses PRINTN macro:

#make_COM# include
'emu8086.inc' ORG 100h
MOV AL, 1
MOV BL, 2
PRINTN 'Hello World!' ; macro. MOV CL, 3
PRINTN 'Welcome!' ; macro. RET

ORG 100h

MOV AL, var1


MOV BX, var2

RET ; stops the program.

VAR1 DB 7

var2 DW 1234h

Copy the above code to the source editor, and press F5 key to compile it and
load in the emulator. You should get something like:
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.

Note: The
MOV
instruction cannot b
used to set
the value of
the CS and IP register

you can type the above program to emu8086 code editor, and press [Compile
and Emulate] button (or press F5 key on your keyboard).

The emulator window should open with this program loaded, click [Single Step]
button and watch the register values.

You should see something like that when program finishes:


Actually the above program writes directly to video memory, so you may see
that MOV is a very powerful instruction.

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.


Encode the above code to emu8086 source editor, and press F5 key to compile
and load it in the emulator. You should get something like:

Arrays

Arrays can be seen as chains of variables. A text string is an example of a byte


array, each character is presented as an ASCII code value (0..255).

Here are some array definition examples:

a DB 48h, 65h, 6Ch, 6Ch, 6Fh, 00h b DB 'Hello', 0

b is an exact copy of the a array, when compiler sees


a string inside quotes it automatically converts it to set of
bytes. This chart shows a part of the memory where these
arrays are declared:

Interrupts
Interrupts can be seen as a number of functions. These functions make the
programming much easier, instead of writing a code to print a character you
can simply call the interrupt and it will do everything for you. There are also
interrupt functions that work with disk drive and other hardware. We call such
functions software interrupts.

Interrupts are also triggered by different hardware; these are called hardware
interrupts. Currently we are interested in software interrupts only.

To make a software interrupt there is an INT instruction, it


has very simple syntax: INT value

Where value can be a number between 0 to 255 (or 0 to 0FFh), generally we


will use hexadecimal numbers. You may think that there are only 256 functions,
but that is not correct. Each interrupt may have sub-functions.

To specify a sub-function AH register should be set before calling interrupt.


Each interrupt may have up to 256 sub-functions (so we get 256 * 256 =
65536 functions). In general AH register is used, but sometimes other registers
maybe in use. Generally other registers are used to pass parameters and data
to subfunction.

The following example uses INT 10h sub-function 0Eh to type a "Hello!"
message. This function displays a character on the screen, advancing the
cursor and scrolling the screen as necessary.

Library of common functions - emu8086.inc


To make programming easier there are some common functions that can be
included in your program. To make your program use functions defined in
another file you should use the INCLUDE directive followed by a file name.
Compiler automatically searches for the file in the same folder where the source
file is located, and if it cannot find the file there - it searches in Inc folder.

Currently you may not be able to fully understand the contents of the
emu8086.inc (located in Inc folder), but it's OK, since you only need to
understand what it can do.

To use any of the functions in emu8086.inc you should have the following line
in the beginning of your source file: Library: include 'emu8086.inc'

emu8086.inc defines the following macros:


PUTC char - macro with 1 parameter, prints out an ASCII char at
current cursor position.
GOTOXY col, row - macro with 2 parameters, sets cursor position.
PRINT string - macro with 1 parameter, prints out a string.
PRINTN string - macro with 1 parameter, prints out a string. The
same as PRINT but automatically adds "carriage return" at the end of
the string.
CURSOROFF - turns off the text cursor. CURSORON
- turns on the text cursor.

Example1:
Example2:

Emu8086 combines an advanced source editor, assembler, disassembler,


software emulator (Virtual PC) with debugger, and step by step tutorials. 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.
Such relatively simple and low-power 8086-compatible processors in CMOS
are still used in embedded systems.

Suggested Reference:
• Hamacher, Carl, (2013) Computer organization and embedded systems
New York: McGraw-Hill, 6th Ed.
• Clements, Alan (2014), Computer organization and
Architecture: Themes and Variations. Stamford, CT: Cengage Learning

You might also like