You are on page 1of 16

Department of: Subject of:

Computer Systems Engineering Computer Architecture and Assembly


Programming
Mehran University of Engineering Year 2nd Semester 3rd
&Technology
Batch 19CS Duration 03
Hours
Jamshoro

Practical no.4
Implementing Data Instructions in Emu8086
Objective:
Learn
 How 8086 executes data instructions

.
Learn how to:
 Write programs in Emu8086 using data instructions
 Write a complete assembly program.
 Use Emu8086 to execute written programs
 Use Emu8086 to execute single instruction at a time.
 Edit an existing source program.

Lab Outcomes:

Practice 8086 Emulator


 Loading, verifying and saving machine code of data instructions.
 Executing data instructions and tracing programs.

1. Data Transfer Instructions: These instructions are used to transfer the data from source
operand to destination operand. All the store, move, load, exchange, input and output
instructions belong to this group.

General purpose byte or word transfer instructions:


(a) MOV : Copy byte or word from specified source to specified destination
(b) PUSH : Push the specified word to top of the stack
(c) POP : Pop the word from top of the stack to the specified location
(d) XCHG : Exchange the contents of the specified source and destination operands one
of which may be a register or memory location.
(e) PUSHA : Push all registers to the stack
(f) POPA : Pop the words from stack to all registers
Task 1 is solved; and you have to solve Task 2 by observing Task 1

Task 1: Write an assembly language program in which you will send three 16-bit
numbers to AX, BX and CX registers respectively. After that PUSH the values of the
registers to the stack. Furthermore, exchange the contents of AL with AH register, BL
with BH register and CL with CH register. Now, POP the values back to AX, BX and
CX registers. Check the final results in the registers and compare it with the previous
values.

Coding in emu8086:
MOV AX,07A2H
MOV BX,1A63H
MOV CX,08C3H
PUSH AX
PUSH BX
PUSH CX
XCHG AL,AH
XCHG BL,BH
XCHG CL,CH
POP AX
POP BX
POP CX
Running emu step by step:

1st step: Storing 07A2 in AX register

Analysis:
Value is stored in AX register and address of IP also changed.
2nd step: Storing 1A63 in BX register.

Analysis:
Value is stored in BX register and address of IP also changed.
3rd step: Storing 08C3 in CX register.

Analysis:
Value is stored in CX register and address of IP also changed.
4th step: Now pushing all the three registers to stack.

Analysis:
All the registers are pushed to stack but address of IP and SP is also changed for each
time when a register is pushed into stack.
5th step: Exchanging the values of AL with AH.

Analysis:
Value of AL and AH are exchanged.
6th step: Exchanging the values of BL with BH.

Analysis:
Values of BL and BH are exchanged.
7th step: Exchanging the values of CL with CH.

Analysis:
Values of CL and CH are exchanged.
8th step: Pop all values of registers from stack.

Analysis:
All values of registers are poped again from stack to registers. But values of AX and
CX are interchanged because stack works on last in first out (LIFO).

As after every command addresses of registers are changed respectively which are analysed
in table 1.
Report

AX BX CX DX CS IP SS SP BP SI DI DS ES
Instructions
AL AH BL BH CL CH DL DH
MOV A2 07 00 00 00 00 00 00 0100 0003 0100 FFFE 0000 0000 0000 0100 0100
AX,07A2H
MOV A2 07 63 1A 00 00 00 00 0100 0006 0100 FFFE 0000 0000 0000 0100 0100
BX,1A63H
MOV A2 07 63 1A C3 08 00 00 0100 0009 0100 FFFE 0000 0000 0000 0100 0100
CX,08C3H
PUSH AX A2 07 63 1A C3 08 00 00 0100 000A 0100 FFFC 0000 0000 0000 0100 0100
PUSH BX A2 07 63 1A C3 08 00 00 0100 000B 0100 FFFA 0000 0000 0000 0100 0100
PUSH CX A2 07 63 1A C3 08 00 00 0100 000C 0100 FFF8 0000 0000 0000 0100 0100
XCHG AL,AH 07 A2 63 1A C3 08 00 00 0100 000E 0100 FFF8 0000 0000 0000 0100 0100
XCHG BL,BH 07 A2 1A 63 C3 08 00 00 0100 0010 0100 FFF8 0000 0000 0000 0100 0100
XCHG CL,CH 07 A2 1A 63 08 C3 00 00 0100 0002 0100 FFF8 0000 0000 0000 0100 0100
POP AX C3 08 1A 63 C3 08 00 00 0100 0013 0100 FFFA 0000 0000 0000 0100 0100
POP BX C3 08 63 1A C3 08 00 00 0100 0014 0100 FFFC 0000 0000 0000 0100 0100
POP CX C3 08 63 1A A2 07 00 00 0100 0015 0100 FFFE 0000 0000 0000 0100 0100

Table no 1

Task #2: Write an assembly language program in which you will send random values
to AX,BX,CX,DX,SI,DI,SP and BP. Push all the values to stack. After that clear all the
registers except SP. Now, Pop all the stack values to the above mentioned register again.
Check the final results and compare with the previous values.

Coding in emu8086:
MOV AX,283AH
MOV BX,83C2H
MOV CX,0928H
MOV DX,1234H
MOV SI,0001H
MOV DI,7300H
MOV SP,0100H
MOV BP,0199H
PUSHA
MOV AX,0000H
MOV BX,0000H
MOV CX,0000H
MOV DX,0000H
MOV SI,0000H
MOV DI,0000H
MOV BP,0000H
POPA
HLT
Running emu step by step:

1st step: Storing 283A in AX register.

Analysis: 283A is stored in AX.(Complete the remaining steps and write analysis)
2nd Step :.

Analysis:.

3rd step:
Analysis:

4th step:
Analysis:

5th step:
Analysis:

6th step:

Analysis:

7th step:
Analysis:

8th step:
Analysis:

9th step:
Analysis:.

10th step:

Analysis:

11th Step:.

Analysis
AX BX CX DX CS IP SS SP BP SI DI DS ES
Instructions
AL AH BL BH CL CH DL DH
MOV
AX,283AH
MOV
BX,83C2H
MOV
CX,0928H
MOV
DX,1234H
MOV
SI,0001H
MOV
DI,7300H
MOV
SP,0100H
MOV
BP,0199H
PUSHA
MOV
AX,0000H
MOV
BX,0000H
MOV
CX,0000H
MOV
DX,0000H
MOV
SI,0000H
MOV
DI,0000H
MOV
BP,0000H
POPA

Fill the below table and write the conclusion in the same way table 1 is filled
Conclusion

You might also like