0% found this document useful (0 votes)
26 views41 pages

8086 Alp's

The document contains a series of assembly language programs for the 8086 microprocessor, demonstrating various arithmetic operations such as addition, multiplication, division, and logical instructions. It also includes algorithms for finding factorials, sums, sorting, and searching within arrays, as well as conversions between binary, BCD, and ASCII formats. Each program is structured with comments and specific memory addresses for data storage and manipulation.

Uploaded by

rumananaaz28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views41 pages

8086 Alp's

The document contains a series of assembly language programs for the 8086 microprocessor, demonstrating various arithmetic operations such as addition, multiplication, division, and logical instructions. It also includes algorithms for finding factorials, sums, sorting, and searching within arrays, as well as conversions between binary, BCD, and ASCII formats. Each program is structured with comments and specific memory addresses for data storage and manipulation.

Uploaded by

rumananaaz28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

8-Bit Addition:

MOV DI,2000H
MOV AL,[DI]
INC DI
ADD AL,[DI]
INC DI
MOV [DI],AL
HLT
16-Bit Addition
MOV DI,2000H
MOV AX,[DI]
INC DI
INC DI
ADD AX,[DI]
INC DI
INC DI
MOV [DI],AX
HLT
8-Bit Multiplication

MOV DI,2000H
MOV AL,[DI]
INC DI
MOV BL,[DI]
MUL BL
INC DI
MOV [DI],AX
HLT
16 Bit Multiplication
MOV DI,2000H
MOV AX,[DI]
INC DI
INC DI
MOV BX,[DI]
MUL BX
INC DI
INC DI
MOV [DI],AX
INC DI
INC DI
MOV [DI],DX
HLT
8-Bit Division
MOV DI,1200H
MOV AL,[DI]
INC DI
MOV BL,[DI]
DIV BL
INC DI
MOV [DI],AL
INC DI
MOV [DI],AH
HLT
16-Bit Division
MOV DI,2000H
MOV AX,[DI]
INC DI
INC DI
MOV BX,[DI]
DIV BX
INC DI
INC DI
MOV [DI],AX ;Quotient in [DI]
INC DI
INC DI
MOV [DI],DX ;Remainder in [DI]
HLT
FACTORIAL of N

MOV SI,2000
MOV CX,0005
MOV AX,0001
UP MUL CX
DEC CX
JNZ UP
MOV [SI],AX
HLT
SUM OF N NATUARAL NUMBERS

MOV SI,2000
MOV CX,0005
MOV AX,0000
UP ADD AX, CX
DEC CX
JNZ UP
MOV [SI],AX
HLT
Sum of Series of 16-Bit Numbers

MOV CX, 0005H ;number of words in CX reg


MOV AX, 0000H ;sum = 0 in accumulator
MOV BX, 0000 H ;carry =0 in BX register
MOV SI, 3000H ;initialize memory pointer SI
MOV DI, 4000 H
UP: ADD AX, [SI] ;add memory word
JNC NEXT
INC BX ;If carry flag set, increment carry
NEXT: ADD SI, 0002H ;increment memory pointer SI
LOOP UP ;repeat until CX = 0
MOV [DI], AX ;store sum
ADD DI, 0002
MOV [DI], BX ;store carry
INT 03 H
SUM OF SQUARES OF “ N” NUMBERS
MOV SI,2000H
MOV CL,[SI]
MOV BX,0000H
MOV DX,0000H
INC SI
BACK MOV AL,[SI]
MUL AL
ADD DX,AX
JNC GOTO
INC BX
GOTO INC SI
LOOP BACK
MOV [SI],DX
INC SI
INC SI
MOV [SI],BX
HLT
LARGEST NUMBER IN AN ARRAY

MOV SI, 2000H


MOV CL, 05H
MOV AL, [SI]
BACK CMP AL, [SI+1]
JNC GOTO
MOV AL, [SI+1]
GOTO INC SI
LOOP BACK
INC SI
MOV [SI], AL
HLT
SMALLEST NUMBER IN AN ARRAY
MOV SI, 2000H
MOV CL, 05H
MOV AL, [SI]
BACK CMP AL, [SI+1]
JC GOTO
MOV AL, [SI+1]
GOTO INC SI
LOOP BACK
INC SI
MOV [SI], AL
HLT
To search for a given number in a series of bytes:

MOV SI, 3000H ; SI is used to point the series


MOV CX, 0005H
MOV BX, 0000H
MOV DI, 2500H
MOV AL, [DI] ; Number to be searched is copied
NEXT: CMP AL, [SI] ;
JE LAST ; Compare it with numbers in
INC SI series if found goto LAST
LOOP NEXT
JZ NOT_FOUND
LAST: MOV BX, 0001H ; if the number is found
.

DATA: 3000: AA, BB, CC, DD, EEH


RESULT:
• If 2500: BB H Then BX: 0001 H [indicates number found]
• If 2500: 15 H Then BX: 0000 H [indicates number not found
.
8086 program to find the square root of a perfect
square root number:
.
Ascending order:
MOV SI, 2500H ; SI is the pointer to the series
MOV DL, 0AH ; Count is stored in DL
DEC DL ; number of comparisons =DL-1
REPEAT: MOV CL, DL
NEXT: MOV AL, [SI] ; copy a number to AL
INC SI
CMP AL, [SI] ; compare with the next number
JC SKIP ; if the first number>second then
MOV BL, [SI] ; no exchange otherwise exchange
MOV [SI], AL ; the two memory location data
DEC SI
MOV [SI], BL
INC SI ; increment the pointer
SKIP: DEC CL ; repeat until CL=0
JNZ NEXT
MOV SI, 2500H
DEC DL ; Go for next pass if DL  0
JNZ REPEAT
INT 3
Output:

• DATA: 2500: F0, 12, 7F, 8D, 9B, A0, 09, 87, 26, 54 H
• RESULT: 2500: F0, A0, 9B, 8D, 87, 7F, 54, 26, 12, 09 H
Descending order:
MOV SI, 2500H ; SI is the pointer to the series
MOV DL, 0AH ; Count is stored in DL
DEC DL ; number of comparisons =DL-1
REPEAT: MOV CL, DL
NEXT: MOV AL, [SI] ; copy a number to AL
INC SI
CMP AL, [SI] ; compare with the next number
JNC SKIP ; if the first number>second then
MOV BL, [SI] ; no exchange otherwise exchange
MOV [SI], AL ; the two memory location data
DEC SI
MOV [SI], BL
INC SI ; increment the pointer
SKIP: DEC CL ; repeat until CL=0
JNZ NEXT
MOV SI, 2500H
DEC DL ; Go for next pass if DL  0
JNZ REPEAT
INT 3
.
.
.
ASCENDING ORDER
MOV SI,2000H
MOV CL,[SI]
DEC CL
REPEAT: MOV SI,2000H
MOV CH,[SI]
DEC CH
INC SI
REPCOM: MOV AL,[SI]
INC SI
CMP AL,[SI]
JC AHEAD
XCHG AL,[SI]
XCHG AL,[SI+1]
AHEAD: DEC CH
JNZ REPCOM
DEC CL
JNZ REPEAT
DESCENDING ORDER

MOV SI,2000H
MOV CL,[SI]
DEC CL
REPEAT: MOV SI,2000H
MOV CH,[SI]
DEC CH
INC SI
REPCOM: MOV AL,[SI]
INC SI
CMP AL,[SI]
JNC AHEAD
XCHG AL,[SI]
XCHG AL,[SI+1]
AHEAD: DEC CH
JNZ REPCOM
DEC CL
JNZ REPEAT
HLT
PROGRAM TO PERFORM BLOCK TRANSFER OF DATA

MOV SI, 6000

MOV DI, 7000

MOV CX, 0006

UP CLD

MOVSB

DEC CX

JNZ UP

HLT
PROGRAM TO PERFORM BLOCK INTERCHANGE

MOV SI, 3000


MOV DI, 7000
MOV CL,05
X1: MOV AL,[SI]
XCHG AL,[DI]
MOV [SI], AL
INC SI
INC DI
DEC CL
JNZ X1
INT 03
Logical Instructions

Example 1:
MOV AX,[1000]
MOV BX,[1002]
AND AX,BX
MOV [2000],AX
HLT
Example 2:
MOV AX,[1000]
MOV BX,[1002]
OR AX,BX
MOV [2000],AX
HLT
.

Example 3:
MOV AX,[1000]
MOV BX,[1002]
XOR AX,BX
MOV [2000],AX
HLT
Example 4:
MOV AX,[1000]
NOT AX
MOV [2000],Ax
HLT
Binary to unpacked BCD
MOV SI, 3000H ; initialize memory pointer
MOV AH, 00H
MOV AL, [SI] ; store the BCD number in Accumulator
MOV CL, 64H ; divide the BCD number with 100
DIV CL R = AH Q =AL  AL/CL
MOV [3001], AL ; store the most significant digit
MOV AL, AH
MOV AH, 00
MOV CL, 0AH ; divide the remainder with 10
DIV CL
MOV [3002], AL ; store the next digit
MOV [3003], AH ; store the last digit
INT 20H
DATA
3000H – FB H
RESULT
3001 – 02
3002 – 05
3003 – 01
AL = 45

BL = 45
BCD TO BINARY CONVERSION PROGRAM

45 ANDED 0F MOV AL, [4000] ; Copy the packed BCD number to


0100 0101
MOV BL, AL
0000 1111 AND BL, 0FH ; Unpack the number
0000 0101 = BL = 05 AND AL, F0H
AL =
MOV CL, 04H
0100 0101 ROR AL, CL
11110000 = MOV BH, 0AH
0100 0000 = AL = 40
MUL BH ; Multiply upper nibble by 10
AL = 04 H ADD AL, BL ; add msd*10 + lsd
MOV [4001], AL
AL *BH = 04 *0A = 28 H
INT 03 H
AL + BL = 28 H +
05
------ DATA RESULT
2D H 4000H – 50 4001 – 32
Convert Packed BCD to Unpacked BCD
Number
MOV SI, [2000]
MOV AL,[SI]
MOV BL, AL
AND BL, 0FH
AND AL, F0H
MOV CL, 04H
ROR AL, CL
MOV [2001], AL
MOV [2002], BL
INT 03 H
Convert Packed BCD to ASCII Number
MOV SI, [2000]
MOV AL,[SI]
MOV BL, AL
AND BL, 0FH
ADD BL,30H
AND AL, F0H
MOV CL, 04H
ROR AL, CL
ADD AL,30H
MOV [2001], AL
MOV [2002], BL
INT 03 H
Convert Packed BCD to ASCII Number
MOV SI, [2000]
MOV AL,[SI]
MOV BL, AL
AND BL, 0FH
AND AL, F0H
MOV CL, 04H
ROR AL, CL
ADD AL,30H
MOV [2001], AL
ADD BL,30H
MOV [2002], BL
INT 03 H
.

Programs
By using
TASM Software
Addition of two 16-bit numbers
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
OPR1 DW 1234H
OPR2 DW 5678H
RESULT DW 01 DUP (0000)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MOV BX, OPR2
CLC
ADD AX, BX
MOV DI, OFFESET RESULT
MOV [DI], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
ADDITION OF TWO 16-BIT NUMBERS

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
OPR1 DW 1234H
OPR2 DW 5678H
RESULT DW 01 DUP (0000)
DATA ENDS

Address Opcode Label Mnemonic Operands Comments

CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MOV BX, OPR2
CLC
ADD AX, BX
MOV DI, OFFESET
RESULT

MOV [DI], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
NUMBER OF EVEN AND ODD NUMBERS FROM A SERIES OF 16-BIT HEXA DECIMAL NUMBERS

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
LIST DW 2358H, 0A579H, 0C322H,0C91EH,0C000H,0957H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
Address Opcode Label Mnemonic Operands Comments

START: XOR BX, BX


XOR DX, DX
MOV AX,DATA
MOV DS, AX
MOV CL,COUNT
MOV SI, OFFSET
LIST
AGAIN MOV AX, [SI]
:
ROR AX, 01
JC ODD
INC BX
JMP NEXT
ODD: INC DX
NEXT: ADD SI, 02
DEC CL
JNZ AGAIN
MOV AH, 4CH
INT 21H
CODE ENDS
END START
ADDITON OF SERIES OF 8-BIT NUMBERS

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
NUMLISTDB 52H,32H, 84H,25H
COUNT EQU 04H
RESULT DW 01H DUP (?)
DATA ENDS
Address Opcode Label Mnemonic Operands Comments
CODE SEGMENT
ORG 200H
START: MOV AX, DATA
MOV DS, AX
MOV CX, COUNT
XOR AX, AX
XOR BX, BX
MOV SI, OFFSET
NUMLIST
AGAIN: MOV BL, [SI]
ADD AX, BX
INC SI
DEC CX
JNZ AGAIN
MOV DI, OFFESET
RESULT
MOV [DI], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
NUMBER OF POSITIVE AND NEGATIVE NUMBERS IN A GIVEN SERIES OF SIGNED NUMBERS

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
LIST DW 2579H, 0A500H, 0C009H, 0159H, 0B900H
COUNTEQU 05H
DATA ENDS
CODE SEGMENT

Address Opcode Label Mnemonic Operands Comments


START: XOR BX, BX
XOR DX,DX
MOV AX, DATA
MOV DS, AX
MOV CL, COUNT
MOV SI, OFFSET LIST
AGAIN: MOV AX, [SI]
SHL AX, 01
JC NEG1
INC BX
JMP NEXT
NEG1: INC DX
NEXT: ADD SI, 02
DEC CL
JNZ AGAIN
MOV AH, 4CH
INT 21H
CODE ENDS
END START

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy