Data Segment Data Ends Code Segment Assume Ds:Data, Cs:Code: 1) 8086/masm Program On Fibonacci Series
Data Segment Data Ends Code Segment Assume Ds:Data, Cs:Code: 1) 8086/masm Program On Fibonacci Series
Data Segment Data Ends Code Segment Assume Ds:Data, Cs:Code: 1) 8086/masm Program On Fibonacci Series
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
MAIN PROC
MOV AH,02H
MOV DL,’1’
INT 21H
MOV DL,’,’
INT 21H
MOV DL,’1’
INT 21H
MOV BL,01H
MOV CH,01H
MOV DL,’,’
INT 21H
START1:
MOV CL,BL
ADD BL,CH
MOV CH,CL
MOV AL,BL
MOV AH,00
MOV BH,10
DIV BH
MOV CL,AH
MOV DL,AL
MOV AH,02H
ADD DL,30H
INT 21H
MOV DL,CL
ADD DL,30H
INT 21H
MOV DL,CL
ADD DL,30H
INT 21H
MOV DL,’,’
INT 21H
CMP BL,50H
JL START1
MOV AX,4C00H
INT 21H
CODE ENDS
END MAIN
***********************
www.esnips.com/user/vapremaims Page 1
2) 8086/Masm Program To Perform The Following Operations.
(A) Reverse A String.
DATA SEGMENT
M1 DB 10,13,'ENTER THE STRING:$'
M2 DB 10,13,'REVERSE OF A STRING:$'
BUFF DB 80
DB 0
DB 80 DUP(0)
COUNTER1 DW 0
COUNTER2 DW 0
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START:MOV AX,DATA
MOV DS,AX
MOV AH,09H
MOV DX,OFFSET M1
INT 21H
MOV AH,0AH
LEA DX,BUFF
INT 21H
MOV AH,09H
MOV DX,OFFSET M2
INT 21H
LEA BX,BUFF
INC BX
MOV CH,00
MOV CL,BUFF+1
MOV DI,CX
BACK:MOV DL,[BX+DI]
MOV AH,02H
INT 21H
DEC DI
JNZ BACK
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
*************************
Output:- Enter the String SR Engineering College
www.esnips.com/user/vapremaims Page 2
3) 8086/Masm Program To Print Factorial Of A Number
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MAIN PROC
MOV AX,0001H
MOV CX,0008H
MOV DX,0000H
L1:
MUL CX
LOOP L1
MOV CX,00
L2:
MOV DX,0000H
MOV BX,0AH
DIV BX
PUSH DX
INC CX
CMP AX,0000H
JE L3
JMP L2
L3:
POP DX
MOV AH,02H
ADD DX,0030H
INT 21H
LOOP L3
END:
MOV AX,4C00H
INT 21H
CODE ENDS
MAIN ENDP
END MAIN
*********************
Output:- 40320
www.esnips.com/user/vapremaims Page 3
4) 8086/Masm Program To Print Numbers From 0-9 and 9-0
CODE SEGMENT
ASSUME CS:CODE
START:
MOV BL,00H
MOV AX,0200H
START2:
MOV DL,BL
ADD DL,30H
INT 21H
MOV DL,’,’
INT 21H
ADD BL,01H
CMP BL,0AH
JL START2
SUB BL,01H
START1:
MOV DL,BL
ADD DL,30H
INT 21H
MOV DL,’,’
INT 21H
SUB BL,01H
CMP BL,00H
JGE START1
MOV AX,4C00H
INT 21H
CODE ENDS
END STAR
**********************
Output:-
0,1,2,3,4,5,6,7,8,9,9,8,7,6,5,4,3,2,1,0
www.esnips.com/user/vapremaims Page 4
5) 8086 MASM PROGRAM TO Read In A Binary String Through Keyboard
And Display It In The Reverse Order.Also Display Its Parity.
ASSUME DS:DATA1,CS:CODE1
DATA1 SEGMENT
MSG DB 0AH,0DH,'ENTER THE BINARY NUMBER$'
NUMBER DB 20,0,20 DUP('$')
MSG2 DB 0AH,0DH,'THE NUMBER IN REVERSED ORDER IS$',0AH,0DH
ODD DB 0AH,0DH,'THE NUMBER HAS ODD PARITY$'
EVENPAR DB 0AH,0DH,'THE NUMBER HAS EVEN PARITY$'
DATA1 ENDS
CODE1 SEGMENT
START:MOV AX,DATA1
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
LEA DX,NUMBER
MOV AH,0AH
INT 21H
MOV BX,0000H
MOV CX,BX
MOV CL,NUMBER+1
LEA SI,NUMBER+2
AGAIN:MOV AX,0001H
AND AL,[SI]
JZ SKIP
INC BX
SKIP:INC SI
LOOP AGAIN
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV CX,0000H
MOV CL,NUMBER+1
DEC SI
DO:
MOV DL,[SI]
MOV AH,02H
INT 21H
DEC SI
LOOP DO
MOV AX,BX
MOV BL,02H
www.esnips.com/user/vapremaims Page 5
DIV BL
AND AH,01H
JNZ ODDPAR
LEA DX,EVENPAR
MOV AH,09H
INT 21H
JMP DOWN
ODDPAR:
LEA DX,ODD
MOV AH,09H
INT 21H
DOWN: MOV AH,4CH
INT 21H
CODE1 ENDS
END START
****************
Output:-
www.esnips.com/user/vapremaims Page 6
6) 8086 /Masm Program To Find Out Whether The Given Year Is A Leap Year
Or Not
ASSUME DS:DATA1,CS:CODE1
DATA1 SEGMENT
MSG DB 0AH,0DH,'ENTER THE YEAR$'
NUMBER DB 6,0,6 DUP('$')
YS DB 0AH,0DH,'YES,IT IS A LEAP YEAR$'
N DB 0AH,0DH,'NO,IT IS NOT A LEAP YEAR$'
DATA1 ENDS
CODE1 SEGMENT
START: MOV AX,DATA1
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
LEA DX,NUMBER
MOV AH,0AH
INT 21H
LEA BX,NUMBER+4
MOV AH,[BX]
MOV AL,[BX+1]
AAD
MOV BL,04H
DIV BL
AND AH,0FFH
JZ YES
LEA DX,N
MOV AH,09H
INT 21H
JMP DOWN
YES:LEA DX,YS
MOV AH,09H
INT 21H
DOWN: MOV AH,4CH
INT 21H
CODE1 ENDS
END START
****************
www.esnips.com/user/vapremaims Page 7
7) 8086 / MASM PROGRAM TO CONVERT THE Given Temperature In
Centigrade(<100°C) To Fahrenheit And Kelvin And Display It (I/P And O/P
As Decimal Numbers)
ASSUME DS:DATA1,CS:CODE1
DATA1 SEGMENT
MSG DB 0AH,0DH,'ENTER THE TEMPERATURE IN DEGREE CELSIUS',0AH,'$'
MSG1 DB 0AH,0DH,'ERROR! ENTER A TEMPERATURE LESS THAN 99
DEGREE C$'
MSG2 DB 0AH,0DH,'THE TEMPERATURE IN KELVIN SCALE IS=$'
MSG3 DB 0AH,0DH,'THE TEMPERATURE IN FARENHEIT SCALE IS
APPROXIMATELY=$'
MSG4 DB 0AH,0DH,'THE TEMPERATURE IN CELSIUS SCALE IS=$'
TEMP DB 6,0,6 DUP('$')
RESULT DB 20,0,20 DUP('$')
DATA1 ENDS
CODE1 SEG
START:MOV AX,SEG DATA1
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
MOV CH,02H
ASK:
LEA DX,TEMP
MOV AH,0AH
INT 21H
LEA DX,MSG4
MOV AH,09H
INT 21H
LEA DX,TEMP+2
MOV AH,09H
INT 21H
DO:
LEA BX,TEMP+1
MOV CL,[BX]
INC BX
MOV AH,[BX]
DEC CL
JZ DOWN
MOV AL,[BX+1]
DEC CL
JZ DOWN1
www.esnips.com/user/vapremaims Page 8
LEA DX,MSG1
MOV AH,09H
INT 21H
JMP ASK
DOWN:
MOV AL,AH
MOV AH,00H
DOWN1:
AND AX,0F0FH
AAD
DEC CH
JZ SECOND
ADD AX,0111H;273 ADDITION
CALL DISPLAY
LEA DX,MSG2
CALL SHOW
JMP DO
SECOND:
MOV CL,09H
MUL CL
MOV CL,05H
DIV CL
MOV AH,00H
ADD AL,20H;HEX EQUIVALENT OF 32
CALL DISPLAY
LEA DX,MSG3
CALL SHOW
JMP OVER
DISPLAY:LEA BX,RESULT+4
MOV DL,03H
MOV CL,0AH
AGAIN:
DIV CL
ADD AH,30H
MOV [BX],AH
DEC BX
MOV AH,00H
DEC DL
JNZ AGAIN
RET
SHOW:
MOV AH,09H
INT 21H
LEA DX,RESULT+2
MOV AH,09H
INT 21H
www.esnips.com/user/vapremaims Page 9
RET
OVER:
MOV AH,4CH
INT 21H
CODE1 ENDS
*************
Output:
www.esnips.com/user/vapremaims Page 10
8) 8086 / MASM PROGRAM To Display The Multiplication Table (First 10
Values) For A Number N(<10d)
ASSUME DS:DATA1,CS:CODE1
DATA1 SEGMENT
MSG DB 0AH,0DH,'ENTER THE NUMBER$'
NUMBER DB 2,0,2 DUP('$')
DECIMAL DB '0','1','2','3','4','5','6','7','8','9'
ANS DB 0AH,'0','*','0','=','0','0','$'
DATA1 ENDS
CODE1 SEGMENT
START;MOV AX,SEG DATA1
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
MOV CX,000AH
MOV DL,0AH
MOV AH,02H
INT 21H
LEA DX,NUMBER
MOV AH,0AH
INT 21H
LEA DX,NUMBER
INC DX
INC DX
MOV DI,DX
MOV BL,[DI]
AND BL,0FH
LEA DX,ANS
INC DX
MOV SI,DX
MOV DL,[DI]
MOV [SI],DL
LEA DX,ANS
INC DX
MOV DI,DX
LEA DX,DECIMAL
MOV SI,DX
AGAIN:LEA DX,ANS
INC DX
MOV DI,DX
MOV AL,[SI]
INC DI
INC DI
MOV [DI],AL
MOV BH,[SI]
MOV AX,0000H
AND BH,0FH
MOV AL,BH
www.esnips.com/user/vapremaims Page 11
MUL BL
AAM
ADD AX,03030H
INC DI
INC DI
MOV [DI],AH
INC DI
MOV [DI],AL
LEA DX,ANS
MOV AH,09H
INT 21H
INC SI
LOOP AGAIN
MOV AH,4CH
INT 21H
CODE1 ENDS
END START
***************
6*0=00
6*1=06
6*2=12
6*3=18
6*4=32
6*5=36
6*6=36
6*7=42
6*8=48
6*9=54
www.esnips.com/user/vapremaims Page 12
9) 8086 / MASM PROGRAM To Input 9 Digits And Display The Second Biggest
Number That Can Be Formed Using Those Digits
ASSUME DS:DATA1,CS:CODE1,SS:STACK1
STACK1 SEGMENT
STORE1 DB 10,0,10 DUP('$')
STACK1 ENDS
DATA1 SEGMENT
MSG DB 0AH,0DH,'ENTER THE 9 DIGIT NUMBER$'
NUMBER DB 12,0,12 DUP('$')
MSG1 DB 0AH,0DH,'THE REARRANGED ORDER IS=$'
DATA1 ENDS
STACK SEGMENT
STORE DB 10,0,10 DUP('$')
STACK ENDS
CODE1 SEGMENT
START:MOV AX,DATA1
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
LEA DX,NUMBER
MOV AH,0AH
INT 21H
MOV CX,0008H
PASS:PUSH CX
MOV CX,0008H
LEA DX,NUMBER+2
MOV SI,DX
AGAIN:MOV AL,[SI]
CMP AL,[SI+1]
JNC DOWN
XCHG AL,[SI+1]
XCHG AL,[SI]
DOWN:
INC SI
LOOP AGAIN
POP CX
LOOP PASS
MOV AL,[SI]
XCHG AL,[SI-1]
XCHG AL,[SI]
LEA DX,MSG1
MOV AH,09H
INT 21H
LEA DX,NUMBER+2
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
www.esnips.com/user/vapremaims Page 13
CODE1 ENDS
END START
***************
Output:-
www.esnips.com/user/vapremaims Page 14
10) 8086 / Masm Program for Adding of Numbers
.model small
.stack 100h
.data
t dw 10
.code
mov ax,@data
mov ds,ax
mov ax,45
add ax,t
mov dl,al
mov ah,02h
int 21h
mov ah,4ch
int 21h
end
************
Output:-
www.esnips.com/user/vapremaims Page 15