Sie sind auf Seite 1von 11

Assignment 1:arithmetic operation

1. Write an ALP to find factorial of number for 8086.


MOV AX, 05H
MOV CX, AX
Back: DEC CX
MUL CX
LOOP back
; results stored in AX
; to store the result at D000H
MOV [D000], AX
HLT
5. Write a program to multiply 2 numbers (16-bit data) for 8086.
Title multiply two numbers
Dosseg
.model small
.stack 100h
.data
Multiplier dw 1234H
Multiplicant dw 3456H
Product dw ?
Written by CHANDRA THAPA (October 2012) 4

.code
MULT proc
MOV AX, @data
MOV DS, AX
MOV AX, Multiplicant
MUL Multiplier
MOV Product, AX
MOV Product+2, DX
MOV AH, 4CH
INT 21H
MULT endp
End MULT
6. Sum of series of 10 numbers and store result in memory location total.
Title Sum of series
Dosseg
.model small
.stack 100h
.data
List db 12,34,56,78,98,01,13,78,18,36
Total dw ?
.code
Main proc
MOV AX, @data
MOV DS, AX
MOV AX, 0000H
Written by CHANDRA THAPA (October 2012) 5

MOV CX, 0AH ; counter


MOV BL, 00H ; to count carry
MOV SI, offset List
Back: ADD AL, [SI]
JC Label
Back1: INC SI
LOOP Back
MOV Total, AX
MOV Total+2, BL
MOV AH, 4CH
INT 21H
Label: INC BL
JMP Back1
Main endp
End Main
7. Write a program to find Largest No. in a block of data. Length of block is 0A. Store
the
maximum in location result.
Title maximum in given series
Dosseg
.model small
.stack 100h
.data
List db 80, 81, 78, 65, 23, 45, 89, 90, 10, 99
Result db ?
Written by CHANDRA THAPA (October 2012) 6

.code
Main proc
MOV AX, @data
MOV DS, AX
MOV SI, offset List
MOV AL, 00H
MOV CX, 0AH
Back: CMP AL, [SI]
JNC Ahead
MOV AL, [SI]
Ahead: INC SI
LOOP Back
MOV Result, AL
MOV AH, 4CH
INT 21H
Main endp
End Main

Fibonacci numbers(method 1)

Title Fibonacii numbers


.model small
.data
no db ?
no1 dw ?
no2 dw ?
msg db 13,10,"Enter the number of Fibonacii numbers to be displayed $"
zerr db 13,10,"Pls enter any other number other than 0$"
ms1 db 13,10,"The fibonacii numbers are",13,10,'$'
.code
start: mov ax,@data
mov ds,ax
lp1: mov ah,09h
lea dx,msg
int 21h
mov ah,01h
int 21h
sub al,'0'
mov bl,al
int 21h
sub al,'0'
mov ah,00h
xchg al,bl
mov bh,0ah
mul bh
add al,bl
mov no,al
mov cl,al
mov ch,00h
cmp al,00h
jne cnt
lea dx,zerr
mov ah,09h
int 21h
jmp lp1
cnt: lea dx,ms1
mov ah,09h
int 21h
mov ax,00h
mov bx,01h
mov no1,ax
mov no2,bx
lp2: call disp
mov ax,no1
mov bx,no2
mov dx,ax
add dx,bx
mov ax,bx
mov bx,dx
mov no1,ax
mov no2,bx
loop lp2
mov ah,4ch
int 21h
disp proc
push cx
mov cx,05h
mov bx,0ah
lp: mov dx,00h
div bx
push dx
loop lp
mov ah,02h
mov cx,05h
lp3: pop dx
add dl,'0'
int 21h
loop lp3
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop cx
ret
disp endp
end start

Assignment 3 string manipulation:


3. Write a program to display string master in computer science. for 8086.
Title display the string
Dosseg
Written by CHANDRA THAPA (October 2012) 2

.model small
.stack 100h
.data
String1 db .Electrical and Electronics Engineering., $
.code
Main proc
MOV AX, @data
MOV DS, AX
MOV AH, 09H
MOV DX, offset String1
INT 21H
MOV AH, 4CH
INT 21H
Main endp
End Main
4. Write a program to reverse the given string for 8086.
Title reverse the given string
Dosseg
.model small
.stack 100h
.data
String1 db .assembly language program., $
Length dw $-String1-1
.code
Written by CHANDRA THAPA (October 2012) 3

Main proc
MOV AX, @data
MOV DS, AX
MOV SI, offset String1
MOV CX, Length
ADD SI, CX
Back: MOV DL, [SI]
MOV AH, 02H
INT 21H
DEC SI
LOOP Back
MOV AH, 4CH
INT 21H
Main endp
End Main
8. Find number of times letter .e. exist in the string .exercise., Store the count at
memory
ans.
Title string operation

Dosseg
.model small
.stack 100h
.data

Written by CHANDRA THAPA (October 2012) 7

String db .exercise., $
Ans db ?
Length db $-String
.code
Main proc
MOV AX, @data
MOV DS, AX
MOV AL,00H
MOV SI, offset String
MOV CX, Length
Back: MOV BH, [SI]
CMP BH, .e.
JNZ Label
INC AL
Label: INC SI
LOOP Back
MOV Ans, AL
MOV AH, 4CH
INT 21H
Main endp
End Main
10. Write an assembly language program to count number of vowels in a given string.
Title to count number of vowels in given line of a text
Dosseg
.model small
.stack 100h
.code
Main proc
MOV AX, @data
MOV DS, AX
MOV SI, offset String ;initialize p
MOV CX, Len ;length in CX register
MOV BL, 00 ;vowel count=0
Written by CHANDRA THAPA (October 2012) 9

Back: MOV AL, [SI]


CMP AL, .a.
JB VOW
CMP AL, .z. ;Convert the character to upper case
JA VOW
SUB AL, 20H
VOW: CMP AL, .A.
JNZ a3
INC BL
JMP a2

a3: CMP AL, .E.


JNZ a4
INC BL
JMP a2
a4: CMP AL, .I.
JNZ a5
INC BL
JMP a2
a5: CMP AL, .O.
JNZ a6
INC BL
JMP a2
a6: CMP AL, .U.
JNZ a2
INC BL
Written by CHANDRA THAPA (October 2012) 10

a2: INC SI
LOOP Back
MOV Vowel, BL
MOV AX, 4C00H
INT 21H
Main endp
.data
String db .The quick brown fox jumped over lazy sleeping dog., $
Len dw $-string
Vowel db ?
End Main
11. Write an 8086 ALP which will input the user name from the keyboard. If the user is
.Pokhara. it will output .The username is valid. else it will output .Invalid user name..
Note: This program is not verified in MASM so, please verify this program. This program can
be
done in the same approach as question 10, which is done above by comparing each character
input.
title input name and comparision
dosseg
.model small
.stack 100h
.data
input db 7 dup(?)
comparestring db 'Pokhara','$'
outputstring1 db 'The username is valid','$'
outputstring2 db 'The username is invalid','$'
.code
main proc
mov ax, @data
mov ds, ax
; read string
mov dx, offset input

assignment 5

LAB_MANNUAL_MP_ Microprocessor lab 17012013.pdf


Programs.pdf

pdf file :

sort the number in ascending order.


Binary search
Descending order
Bubble sort

Assignment 6

5.Program involving bit manipulation instruction


i)If given data is positive or negative
DATA SEGMENT
NUM DB 12H
MES1 DB 10,13,'DATA IS POSITIVE $'
MES2 DB 10,13,'DATA IS NEGATIVE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1
JC NEGA
;Move the Number to AL.
;Perform the rotate left side for 1 bit position.
;Check for the negative number.
MOV DX,OFFSET MES1 ;Declare it positive.
JMP EXIT ;Exit program.
NEGA: MOV DX,OFFSET MES2;Declare it negative.
EXIT: MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Data is positive
Positive Numbers: 00-7F
Negative numbers: 80-FF

- 29 ii)If given data is odd or even


DATA SEGMENT
X DW 27H
MSG1 DB 19,13,'NUMBER IS EVEN$'
MSG2 DB 10,13,'NUMBER IS ODD$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,X
TEST AX,01H
JNZ EXIT

LEA DX,MSG1
MOV AH,09H
INT 21H
JMP LAST
;Test for Even/Odd number.
;If it is Even go to Exit label.
;(alternate logic)
;MOV BL,2
;DIV BL
;CMP AH,0H
;JNZ EXIT
;Declare it is Even number.
EXIT: LEA DX,MSG2 ;Declare it is Odd number.
MOV AH,09H
INT 21H
LAST: MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Number is ODD
- 30 iii) Logical ones and zeros in a given data
DATA SEGMENT
X DB 0AAH
ONE DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,X
MOV BL,8
MOV CL,1
UP: ROR AH,CL
JNC DOWN

INC ONE
JMP DOWN1
DOWN: INC ZERO
DOWN1: DEC BL
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Ones--------04
Zeros--------04
;Initialize BL to 8.
;Initialize CL to 1.
;Perform the single bit rotate operation
;with respect to right.
;If no carry go to DOWN label.
;Increment one.
;Jump to DOWN1.
;Increment ZERO.
;Decrement the BL.
;If no zero go to UP label.
- 31 iv) 2 out of 5 code
DATA SEGMENT
X DW 82H
MES DB 10,13,'VALID 2 OUT OF CODE $'
MES1 DB 10,13,'NOT A VALID 2 OUT OF CODE $'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,X
MOV BX,0H
AND AX,0E0H
JNZ DISP
MOV CL,05
MOV AX,X
UP: ROR AX,1
JNC DOWN
INC BX
DOWN:DEC C
JNC UP
CMP BX,02H
JNZ DISP
LEA DX,MES
MOV AH,09H
INT 21H
JMP EXIT
DISP: LEA DX,MES1

MOV AH,09H
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Not a valid 2 out of 5 code.
;Load the Data to AX.
;Move the Data AX to DS.
;Move the Data word to AX.
;Initialize the BX.
;Perform the AND operation of first 3 bit.
;If no zero jump to DISP label.
;If zero, Initialize the counter for check the last 5 bit.
;Move the Data word to AX.
;Rotate right side one time.
;If no carry jump to DOWN label.
;Increment the BX.
;Decrement the counter.
;If no carry jump to UP label.
;Compare the BX with 2.
;If no zero jump to DISP label.
;Declared as 2 out of 5 code .
;Declared as not valid code .
- 32 v) Bit wise palindrome
DATA SEGMENT
X DW 0FFFFH
MSG1 DB 10,13,'NUMBER IS PALINDROME$'
MSG2 DB 10,13,'NUMBER IS NOT PALINDROME$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,X
MOV CL,10H
UP: ROR AX,1
RCL DX,1
LOOP UP
CMP AX,DX
JNZ DOWN
LEA DX,MSG1
MOV AH,09H
INT 21H
JMP EXIT
DOWN: LEA DX,MSG2
MOV AH,09H
INT 21H
EXIT:MOV AH,4CH

INT 21H
CODE ENDS
END START
Output: Number is Palindrome
;Load the Data to AX.
;Move the Data AX to DS.
;Move DW to AX.
;Initialize the counter 10.
;Rotate right one time.
;Rotate left with carry one time.
;Loop the process.
;Compare AX and DX.
;If no zero go to DOWN label.
;Declare as a PALINDROME.
;Jump to EXIT label.
; Declare as not a PALINDROME

Das könnte Ihnen auch gefallen