Sie sind auf Seite 1von 9

02-10-06, Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

2: 80x86 Emulator Part I


1. Introduction
To be able to use the 80x86 Assembler and Microprocessor Emulator.
2. Theory
Everything for learning assembly language in one pack! Emu8086 combines an advanced
source editor, assembler, disassembles, 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.
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 micro-processors
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.
Emu8086 has a much easier syntax than any of the major assemblers, but will still generate a
program that can be executed on any computer that runs 8086 machine code; a great combination
for beginners!
Note: If you don't use Emu8086 to compile the code, you won't be able to step through your actual
source code while running it.
3. Equipment Used
DELL, and COMPAQ Pentium4 PCs with the Licensed 80x86 Emulator.
4. Procedures
Write down the provided assembly programs (check the appendix) L3P2, L3P3, L4P1
(watch the XLAT), L4P2, and L4P4. Run these programs step by step and explain each of one in the
full details.

1/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

5. Questions
5.1 Try to execute the upper procedure using DEBUG program, show all of your details.
5.2 Also try to use either Microsoft Assembler (MASM, and LINK), or turbo assembler to
run the upper procedure.

6. References,
6.1 http://www.emu8086.com, and info@emu8086.com.
6.2 Lab Manual to accompany the 8088 and 8086 Microprocessors, 2ed, Walter A.
Triebel, Avtar Singh (2000).

7. Appendix
TITLE

BLOCK-MOVE PROGRAM, L3P2 , MASM, Standard Assembly

PAGE

, 132

; This program moves a block of specified number of bytes


; From one place to another place
; Define constants used in this program
N

16

; Bytes to be moved

BLK1ADDR=

100H

; Source block offset address

BLK2ADDR=

120H

; Destination block offset address

DATASEGADDR=
STACK_SEG
DB

2000H

; Data segment start address

SEGMENT

STACK 'STACK'

64 DUP (?)

STACK_SEG

ENDS

CODE_SEG

SEGMENT

BLOCK

PROC

'CODE'
FAR

ASSUME CS: CODE_SEG, SS: STACK_SEG


; To return to DEBUG program put return address on the stack
PUSH

DS

MOV

AX, 0

PUSH

AX

; Set up the data segment address


MOV

AX, DATASEGADDR

2/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

MOV

DS, AX

; Set up the source and destination offset addresses


MOV

SI, BLK1ADDR

MOV

DI, BLK2ADDR

;Set up the count of bytes to be moved


MOV

CX, N

; Copy source block to destination block


NXTPT: MOV
MOV

AH, [SI]

; Move a byte

[DI], AH

INC

SI

;Update pointers

INC

DI

DEC

CX

JNZ

NXTPT

; Update byte counter


; Repeat for next byte

RET

; Return to DEBUG program

BLOCK

ENDP

CODE_SEG

ENDS

END

BLOCK

; End of program L3P2

TITLE

BLOCK-MOVE PROGRAM, L3P3


PAGE

, 132

; This program moves a block of specified number of bytes


; From one place to another place

; Define constants used in this program


N

16

; Bytes to be moved

BLK1ADDR=

100H

; Source block offset address

BLK2ADDR=

120H

; Destination block offset address

DATASEGADDR=
STACK_SEG

SEGMENT
DB

STACK_SEG

ENDS

CODE_SEG

SEGMENT

BLOCK

2000H

PROC

; Data segment start address

STACK 'STACK'
64 DUP(?)

'CODE'
FAR

ASSUME CS:CODE_SEG,SS:STACK_SEG

3/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

; To return to DEBUG program put return address on the stack


PUSH

DS

MOV

AX, 0

PUSH

AX

; Set up the data segment address


MOV

AX, DATASEGADDR

MOV

DS, AX

; Set up the source and destination offset addresses


MOV

SI, BLK1ADDR

MOV

DI, BLK2ADDR

; Set up the count of bytes to be moved


MOV

CX, N

; Copy source block to destination block


NXTPT: MOV
MOV

AH, [SI]
[DI], AH

INC

SI

DEC

DI

DEC

CX

JNZ

NXTPT

;Update pointers
; Update byte counter
; Repeat for next byte

RET
BLOCK

; Move a byte

; Return to DEBUG program


ENDP

CODE_SEG
END

ENDS
BLOCK

; End of program L3P3

TITLE LAB L4P1


PAGE
STACK_SEG

,132
SEGMENT
DB

STACK 'STACK'
64 DUP(?)

STACK_SEG

ENDS

DATA_SEG

SEGMENT

'DATA'

TABL1

DB

0FFH,0FEH,0FDH,0FCH,0FBH,0FAH,0F9H,0F8H

TABL2

DB

0AH,0BH,0CH,0DH,0EH,0FH,10H,11H

MEM1

DB

MEM2

DB

DATA_SEG

ENDS

CODE_SEG

SEGMENT

L4P1

'CODE'

PROC FAR
ASSUME

CS: CODE_SEG, SS: STACK_SEG, DS: DATA_SEG

4/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

; To return to DEBUG program put return address on the stack


PUSH DS
MOV

AX, 0

PUSH AX
; Following code implements Lab 4 Part 1
MOV

AX, DATA_SEG

MOV

DS, AX

MOV

AL, MEM1

; Establish data segment


; Get the given code

MOV

BX, OFFSET TABL1

XLAT

TABL1

MOV

MEM1, AL

; Save new code

MOV

AL, MEM2

; Repeat for 2nd code

MOV

BX, OFFSET TABL2

XLAT

TABL2

MOV

MEM2, AL

; Translate

RET
L4P1

; Return to DEBUG program

ENDP

CODE_SEG
END

ENDS
L4P1

TITLE L4P2; standard assembly


PAGE
STACK_SEG

, 132
SEGMENT
DB

64 DUP(?)

STACK_SEG

ENDS

DATA_SEG

SEGMENT

NUM1

DB

45H

NUM2

DB

72H

NUM3

DB

DATA_SEG

ENDS

CODE_SEG

SEGMENT

L4P2

STACK 'STACK'

'DATA'

'CODE'

PROC FAR
ASSUME

CS:CODE_SEG, SS:STACK_SEG, DS:DATA_SEG

5/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

; To return to DEBUG program put return address on the stack


PUSH DS
MOV

AX, 0

PUSH AX
; Following code implements Lab 4 Part 2
MOV

AX, DATA_SEG

MOV

DS, AX

MOV

AL, NUM2

;Get the 2nd number

SUB

AL, NUM1

;Subtract the binary way

DAS
MOV

;Establish data segment

;Apply decimal adjustment


NUM3, AL

RET
L4P2

;Save the result


;Return to DEBUG program

ENDP

CODE_SEG
END

ENDS
L4P2

TITLE L4 P4
PAGE
STACK_SEG

, 132
SEGMENT
DB

64 DUP (?)

STACK_SEG

ENDS

CODE_SEG

SEGMENT

L4P4

PROC FAR
ASSUME

STACK 'STACK'

'CODE'

CS: CODE_SEG, SS: STACK_SEG

; To return to DEBUG program put return address on the stack


PUSH DS
MOV

AX, 0

PUSH AX
; Following code implements Lab 4 Part 4
MOV

BX, 0AA55H

MOV

CL, 5

SHR

BX, CL

AND

BX, 0F0FH

RET
L4P4

; Return to DEBUG program

ENDP

CODE_SEG

ENDS

6/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

END

L4P4

Title block move using emulator


;******************************
Data_old db 0ffh,0ffh,0ffh,0ffh,0ffh,0ffh
Data_new db 6 dup(?)
;******************************
Start

proc far
mov ax, @data
mov ds,ax

;******************************
mov si,offset data_old
mov di,offset data_new
mov cx,06h
next:

mov al,[si]
mov [di],al
inc si
inc di
loop next

;******************************
mov ah, 4ch
int 21h
Start

endp
end Start

;******************************

Title block move using emulator and ORG


;******************************
Data_source
Data_in
Data_dest

db 'Muhammed Al-Ani'

db 30h dup(20h)
db 15 dup(?)

;******************************
Start

proc far
mov ax, @data
mov ds,ax

;******************************
mov si, offset data_source
mov di, offset data_dest
mov cx,0fh

7/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

next:

mov al,[si]
mov [di],al
inc si
inc di
loop next

;******************************
mov ah, 4ch
int 21h
Start

endp
end Start

;******************************

;page 61 Mazidi using emulator


Data dw 234dh,1de6h,3bc7h,566ah
sum dw ?
;*******************************
start

proc far
mov ax, @data
mov ds, ax

;*******************************
mov cx, 04h
mov bx, 0
mov di, offset data
next:

add bx, [di]


add di,02
loop next
mov si, offset sum
mov [si], bx
mov ah, 4ch
int 21h

start

endp
end start

Data dw 234dh,0de6h,38c7h,566ah ; using emulator


sum dw ?
start

proc far
mov ax, @data
mov ds, ax

8/9

Microprocessors Lab Manual, LAB2, 80x86 Emulator, Part I

mov cx, 04h


mov bx, 0
mov di, offset data
next:

add bx, [di]


add di,02
loop next
mov si, offset sum
mov [si], bx
mov ah, 4ch
int 21h

start

endp
end start

;count unmber of ones in a two bytes word , first 97f4, and then 97fa ; using emulator
data dw 97f4h; 1001 0111 1111 0100
count db ?
start

proc far
mov ax, @data
mov ds,ax
sub al,al
mov cx,16
mov bx,data

up:

ror bx,1 ; or even shl


jnc down ; jnc to count "1s", and jc to count "0s"
add al,1
daa ; to converts to BCD

down: loop up
mov count,al
mov ah, 4ch
int 21h
start

endp
end start

9/9

Das könnte Ihnen auch gefallen