Professional Documents
Culture Documents
8086 Alp Ppts-Final 02
8086 Alp Ppts-Final 02
8086 Alp Ppts-Final 02
• PUSHF
(SP-1) ← FLAG_HIGH
(SP-2) ← FLAG_LOW
SP ← SP – 2
PUSH & POP (Contd.)
• POPF
FLAG_LOW ← (SP)
FLAG_HIGH ← (SP+1)
SP ← SP + 2
Program 15: MOVing String Transparently
STRMOV PROC FAR
; Input to this procedure is count in CX and addresses in SI & DI.
PUSH SI ; Push SI.
PUSH DI ; Push DI.
PUSH CX ; Push CX.
CLD ; Auto Increment mode.
REP MOVSB ; Transfer string characters.
POP CX ; Restore registers in LIFO manner.
POP DI
POP SI
RET ; Back to Caller Program.
STRMOV ENDP
* Since original values in the registers are restored before going back to
caller program, execution of this procedure is transparent to caller
program.
Program 16: Scanning String Transparently
STRSCN PROC FAR
; Input to this procedure is count in CX and addresses in SI & DI.
PUSHF ; Push Registers.
PUSH DI
PUSH AX
PUSH CX
MOV AH, ‘N’ ; Code for NO MATCH, Match Not Found.
MOV AL, TOSEARCH ; Load Character to search.
CLD ; Auto Increment mode.
REPNE SCASB ; Search all characters while match not found.
JNZ DN1 ; Match Found? NO!! Go to end.
MOV AH, ‘E’ ; YES!! Match Found, Store ‘Y’ as Code.
DN1: MOV RESULT1, AH ; Store the result.
POP CX ; Restore registers in LIFO manner.
POP AX
POP DI
POPF
RET ; Back to Caller Program.
STRSCN ENDP
Program P17: Comparing String Transparently
STRCMP PROC FAR
; Input to this procedure is count in CX and addresses in SI & DI.
PUSHF ; Push Registers.
PUSH DI
PUSH SI
PUSH AX
PUSH CX
CLD ; Auto Increment mode.
MOV AH, ‘G’ ; Code for No Error i.e. GOOD.
REPE CMPSB ; Compare string characters.
JZ DN1 ; Error Found? NO!! Go to end.
MOV AH, ‘E’ ; YES!! Error Found, Store ‘E’ in DL
DN1: MOV RESULT2, AH ; Store the result.
POP CX ; Restore registers in LIFO manner.
POP AX
POP SI
POP DI
POPF
RET ; Back to Caller Program.
STRCMP ENDP
Initializing Stack Simplified
• In stack every location should be a word location to
facilitate 16-bit read & write.
• Load the Most Significant 4-digits of starting address in SS.
• Get to ending address of stack and add 1. Load the least
significant 4-digits in SP.
D_SEG SEGMENT
ASCII_STR DB 76, 48, 99, 119, ………….65
RESULT1 DB
RESULT2 DB
TOSEARCH DB ‘A’
D_SEG ENDS
E_SEG SEGMENT
TARGET DB 100 DUP(00)
E_SEG ENDS
S_SEG SEGMENT
DW 50H DUP(?)
STACK_TOP EQU THIS WORD
S_SEG ENDS
Program P18 (Contd.)
C_SEG SEGMENT
ASSUME CS:C_SEG , DS:D_SEG, ES:E_SEG
STRMOV PROC FAR
:
Program P15
:
STRMOV ENDP
STRSCN PROC FAR
:
Program P16
:
STRSCN ENDP
STRCMP PROC FAR
:
Program P17
:
STRCMP ENDP
Program P18 (Contd.)
MAIN: PROC FAR
MOV AX, E_SEG ; Load ES Register
MOV ES, AX
MOV AX, D_SEG ; Load DS Register
MOV DS, AX
MOV AX, S_SEG ; Load DS Register
MOV SS, AX
LEA SP, STACK_TOP
LEA SI, ASCII_STR ; Load Source offset.
LEA DI, TARGET : Load Destination Offset.
MOV CX, 100 ; Count of Character
CALL STRMOV ; Go to Transfer String.
CALL STRSCN ; Go to Scan String.
CALL STRCMP ; Go to Compare String.
MAIN ENDP
C_SEG ENDS
END MAIN
A Simple Program (P19)
Write an 8086 ALP to set Flag Status as SF=1,
ZF=0, AC=1, CY=0, PF=1, OF=0, DF=0, IF=1
and TF=1.
FLAG: XXXX OF DF IF TF SF ZF X AC X PF X CY
0000 0 0 1 1 1 0 0 1 0 1 0 0
= 0394H
MOV CX, 0394H
PUSH CX
POPF
• This is the only method to affect TRAP flag.
Program (P19) BCD SUBTRACTION
BCDS PROC FAR
MOV AL, BCD1 ; Get first BCD in AL.
MOV CL, BCD2 ; Get second BCD in CL.
SUB AL, CL ; Perform Binary Subtraction.
DAS ; Adjust Result for BCD
MOV RESULT, AL ; Store result in memory.
RET ; Back to Caller Program.
BCDS ENDP
DAA: It adjust AL register for BCD, after binary addition. The DAA
gives correct result only and only if binary addition was
performed on valid BCD number.
A Simple Program (P21)
Two BCD numbers are stored in memory.
Choice of operation on these numbers is
entered by the users at a memory location
CHOICE. Write an 8086 ALP that checks the
user choice such that if CHOICE=1 the
program should perform Addition, otherwise
the program should perform subtraction.
Program P21 (Contd.)
S_SEG SEGMENT
DW 50H DUP(?)
STACK_TOP EQU THIS WORD
S_SEG ENDS
D_SEG SEGMENT
CHOICE DB
BCD1 DB 34H
BCD2 DB 56H
RESULT DB
D_SEG ENDS
C_SEG SEGMENT
ASSUME CS:C_SEG, DS:D_SEG, SS:S_SEG
Program P21 (Contd.)
; Input to the procedures are through AL & BL
BCDA PROC FAR
ADD AL, CL ; Perform Binary Addition.
DAA ; Adjust Result for BCD
MOV RESULT, AL ; Store result in memory.
RET ; Back to Caller Program.
BCDA ENDP