Experiment 04 EEE 3210
Experiment 04 EEE 3210
Experiment 04 EEE 3210
Theory:
There are four fields in an instruction:
• Label
• Op-code (Operation code )
• Operands
• Comments
Example: MOV CX, DX; Copy
1. Immediate Addressing Mode: In this type of addressing mode the source operand is 8 bit or
16 bit data.
Apparatus:
• Emulator8086 Software.
Procedure:
1. First of all, you need to start emu8086. Double-click the emu8086 icon or run
c:\emu8086\emu8086.exe
3. A code example with a lot of comments should open, all comments are green and they take
about 90% of all text, so don't be scared by this tiny "Hello Word" code. The compiled
executable has length of just about 100 bytes, this is even less than the size of this sentence.
4. To run this example in the emulator click emulate (or press F5). This makes the assembler
try to assemble and save the executable to c:\emu8086\MyBuild and then, if the assembler
succeeds in making the file, the emulator will automatically load it into the memory.
5. You can click a single step (or press F8) to execute the code and see how it works, you can
also click step back (or press F6) and see how changes are reversed.
6. Actually, there is far more than a single way to print "Hello World" in assembly language,
and this is not the shortest way. Click examples and browse c:\emu8086\examples, there is
HelloWorld.asm that is assembled in only 30 bytes, it is so small because, unlike the
previous example that does everything itself, the shorter one uses the built-in interrupt
function of the operating system. Interrupts save a lot of work and time, but unlike the
previous example, they often do not let you see how they do what they do.
• To write a new code follow the following steps-
7. Start emulator8086.
8. To write a new code click on New and choose code template as empty workspace.
9. Write the code in the text area.
10. Click on File\Save and save it.
11. Click on Compile\Save\Run. After the operation is completed the emulator will display a
message.
12. Click on debug and verify the output on debug log.
13. For observing output from the trainer kit, enter the Machine code in MDA manually from
location 0000:1000 as default CS=0000 and IP=1000 at startup.
14. Press GO to execute your program or STP to execute single instructions one after another
and fill up the following data tables.
Program 01:
Write the following code in the text area and verify the output.
ORG 1000H
MOV AX, 1223H
MOV BX, 3456H
MOV CX, 6478H
MOV DX, 3386H
HLT
Output:
AX = 1223H
BX = 3456H
CX = 6478H
DX = 3386H
Program 02:
Now again write the following code in the text area and find the problems and solve them.
ORG 1000H
MOV [AX], 1223H
MOV SS, 3456H
MOV CX, 6478H
MOV DX, 3386H
HLT
Discussion:
Questions:
1. Write the following code in the text area, find out the problems, solve them, and Identify which
addressing mode is used in each line.
ORG 1000H
MOV AX, 1000H
MOV BX, 1200H
MOV [AX], 1223H
MOV SS, 3456H
MOV SI, F478H
MOV BX, [SI+2]
MOV AX, [BX+2]
HLT
Objectives:
• To be familiar with stack operations.
• To know how data are stored and removed from stack memory.
Theory:
Stack Memory Addressing:
• Stack holds the data temporarily and stores the return addresses used by the procedures.
• The stack memory is an LIFO (Last in, First out) memory that describes the way that data
are stored and removed from the memory.
• Data are stored into the stack with a PUSH instruction and removed with a POP
instruction.
• The CALL instruction also uses the stack to hold the return addresses for procedures and
a RET (Return) instruction to remove the return address from the stack.
• The stack memory is maintained by 2 registers: Stack Pointer (SP) and Stack Segment
(SS)
• Whenever data is pushed onto the stack, the higher 8 bits are placed in the location SP-1
and the lower 8 bits are placed in the location addressed by SP-2
• Whenever data is popped from the stack, the lower 8 bits are removed from the location
SP and the higher 8 bits are removed from the location addressed by SP+1.
Stack is a segment where some register values can be stored so that it is not lost. In assembly
language programming we have only four registers with which we can perform operations. These
are AX, BX, CX and DX. But in many problems we may need a lot of registers. So we need to
reuse these registers again and again. This can be done by storing present value of a register
(suppose AX) in stack segment. Now we can perform other tasks with AX. This will certainly
change content of AX. After this getting the value of AX from stack and restoring its previous
value. The first job (storing value of AX in stack) is done by PUSH command. Second job
(restoring value of AX from stack) is done by POP command in assembly language. A simple
program can clarify this.
Apparatus:
1. Emulator 8086 Software.
Procedure:
2. Start emulator8086.
3. To write the code click on New and choose the code template as empty workspace.
4. Write the following code in the text area.
Program 01:
ORG 1000H
MOV AX, 3256H; Stores 3256H in AX. This is AX’s original value
PUSH AX; Puts AX’s value in stack
MOV AX, 1254H; AX is assigned to an intermediate value 1254H
DEC AX; New value of AX is 1253H. Certainly AX’s value is changed.
MOV BX, AX; Value of AX is now copied to BX
POP AX; This restores AX’s previous value and now AX is 3256H
HLT
5. Click on File\Save and save it.
6. Click on Compile\Save\Run. After the operation is completed the emulator will halted.
7. Click on debug and verify the output on debug log.
Output:
AX = 3256H, BX=1253H
8. To use specific starting address of stack memory, we will define it by stack segment (SS)
and stack pointer (SP)
Program 02:
ORG 1000H
MOV BX, 1000H
MOV SS, BX
MOV SP, 0001H
MOV AX, 2347H
MOV BX, 1254H
PUSH AX
ADD AX, BX
MOV DX, AX;
POP AX
HLT
9. Click on debug and verify the output on debug log and also click on stack to see the final
address of stack memory.
Discussion:
Questions:
1. Write an assembly language program to interchange the content of the AX and BX register using
PUSH and POP instruction.