Implementing JUMP, PUSH, POP, IN & OUT in Assembly Program on 8086

Manipulating registers and memory efficiently using instructions like JUMP, PUSH, POP, IN, and OUT is essential in assembly language programming. This program demonstrates these operations in 8086 assembly, utilizing stack operations and port I/O.

data segment
abc dw 1101H
def dw 0025H
pqr dw 0011H
res dw ?
res1 dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,abc
mov bx,def
mov cx,pqr
mov dx,0002H
jmp ma
back:
push ax
push bx
push cx
pop cx
pop bx
pop ax
mov ax,abc
inc ax
mov abc,ax
mov bx,def
dec bx
mov def,bx
ma:
add ax,bx
mov res,ax
dec dx
jnz back
in ax,25H
out 30H,ax
mov res1,ax
int 3
code ends
end start

Step-by-Step Explanation

  1. Data Segment Initialization
    • abc dw 1101H, def dw 0025H, pqr dw 0011H: Define variables storing hexadecimal values.
    • res dw ?, res1 dw ?: Reserve memory for storing results.
  2. Code Execution Flow
    • mov ax, data and mov ds, ax: Initializes the data segment by loading its address into AX and then into DS.
    • mov ax, abc: Loads the value of abc into AX.
    • mov bx, def: Loads the value of def into BX.
    • mov cx, pqr: Loads the value of pqr into CX.
    • mov dx, 0002H: Sets up a counter in DX.
    • jmp ma: Jumps to the label ma, skipping the back section initially.
  3. Loop (back: label)
    • push ax: Pushes AX onto the stack.
    • push bx: Pushes BX onto the stack.
    • push cx: Pushes CX onto the stack.
    • pop cx: Pops the last pushed value into CX.
    • pop bx: Pops the previous value into BX.
    • pop ax: Pops the first pushed value into AX.
    • mov ax, abc: Loads abc into AX.
    • inc ax: Increments AX.
    • mov abc, ax: Updates abc with the incremented value.
    • mov bx, def: Loads def into BX.
    • dec bx: Decrements BX.
    • mov def, bx: Updates def with the decremented value.
  4. Label (ma:)
    • add ax, bx: Adds AX and BX, storing the result in AX.
    • mov res, ax: Stores the result in res.
    • dec dx: Decreases DX counter.
    • jnz back: If DX is not zero, jumps back to back, continuing the loop.
  5. I/O Operations
    • in ax, 25H: Reads input from port 25H into AX.
    • out 30H, ax: Outputs the value in AX to port 30H.
    • mov res1, ax: Stores the input value into res1.
    • int 3: Generates a breakpoint interrupt.


Output

C:\TASM>masm pushpop.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987.  All rights reserved.
 
Object filename [pushpop.OBJ]:
Source listing  [NUL.LST]:
Cross-reference [NUL.CRF]:
 
  50402 + 450254 Bytes symbol space free
 
      0 Warning Errors
      0 Severe  Errors
 
C:\TASM>link pushpop.obj
 
Microsoft (R) Overlay Linker  Version 3.60
Copyright (C) Microsoft Corp 1983-1987.  All rights reserved.
 
Run File [PUSHPOP.EXE]:
List File [NUL.MAP]:
Libraries [.LIB]:
LINK : warning L4021: no stack segment
 
C:\TASM>debug pushpop.exe
-g
 
AX=1818  BX=0024  CX=0011  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0B97  ES=0B87  SS=0B97  CS=0B98  IP=003B   NV UP EI PL ZR NA PE NC
0B98:003B CC            INT     3
-d 0B97:0000
0B97:0000  02 11 24 00 11 00 26 11-18 18 00 00 00 00 00 00   ..$...&.........
0B97:0010  B8 97 0B 8E D8 A1 00 00-8B 1E 02 00 8B 0E 04 00   ................
0B97:0020  BA 02 00 EB 17 90 50 53-51 59 5B 58 A1 00 00 40   ......PSQY[X...@
0B97:0030  A3 00 00 8B 1E 02 00 4B-89 1E 02 00 03 C3 A3 06   .......K........
0B97:0040  00 4A 75 E2 E5 25 E7 30-A3 08 00 CC E5 5D C3 90   .Ju..%.0.....]..
0B97:0050  55 8B EC 81 EC 84 00 C4-5E 04 26 80 7F 0A 00 74   U.......^.&....t
0B97:0060  3E 8B 46 08 8B 56 0A 89-46 FC 89 56 FE C4 5E FC   >.F..V..F..V..^.
0B97:0070  26 8A 47 0C 2A E4 40 50-8B C3 05 0C 00 52 50 E8   &.G.*[email protected].
-q

Summary of Execution

  • The program demonstrates the use of JUMP, PUSH, POP, IN, and OUT instructions.
  • The stack is utilized to temporarily store and retrieve register values.
  • Arithmetic operations modify values dynamically within a loop.
  • Input and output ports are accessed using the IN and OUT instructions.
  • The final values are stored before the program ends with an interrupt (int 3).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.