Microprocessor Assignment
Microprocessor Assignment
.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
.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)
.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
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
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
pdf file :
Assignment 6
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