0% found this document useful (0 votes)
5 views11 pages

Lab 10

The document outlines a lab assignment focused on programming with the 8086 microprocessor, including tasks such as calculating sums, counting words and vowels in strings, and displaying results in both decimal and hexadecimal formats. It consists of multiple programs that demonstrate various functionalities of assembly language and user input handling. The lab aims to enhance familiarity with the 8086 architecture and its interrupt instructions.

Uploaded by

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

Lab 10

The document outlines a lab assignment focused on programming with the 8086 microprocessor, including tasks such as calculating sums, counting words and vowels in strings, and displaying results in both decimal and hexadecimal formats. It consists of multiple programs that demonstrate various functionalities of assembly language and user input handling. The lab aims to enhance familiarity with the 8086 architecture and its interrupt instructions.

Uploaded by

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

Lab 10

;1. Write a program to find the sum of numbers from 1 to n. Read n from the user
and display the sum as the decimal format.
;(also try to display the sum in Hexadecimal format)
; ascii --> value sub 30h
;
; THIS SOVLE UP TO 3 DIGIT
.model small
.stack 32
.data
str db "enter the number: $"
max db 4
len db ?
num db 4 dup('?')
sum dw 00
.code
main proc far
mov ax, @data
mov ds, ax

; display message
lea dx, str
mov ah, 09h
int 21h
; read n
mov ah, 0ah
lea dx, max
int 21h
;ascii to hex
call aschex

; caluclate
; mov cx, 00h
;mov cl, num

back:
add sum ,cx
loop back

; display
mov ah, 02h
; break line
mov dl, 0ah
int 21h
mov ax, sum
mov dx, 00h
call display
; terminate
mov ax, 4c00h
int 21h

Microprocessor Page 1
int 21h
main endp
display proc
; ax = value
mov cx, 00h
back2 :
mov dx, 00h
mov bx, 10
div bx ; dx = rem, ax = quotient
add dx, 30h; ascii to value
push dx
add cx, 1h
cmp ax, 00h
jne back2
mov ah, 02h
pooop:
pop dx
int 21h
loop pooop
ret
display endp
aschex proc
; LOGIC D0+D1*A+D2*A*A
mov dl, len
mov dh, 00h
mov di, dx
dec di ; max index
mov cx, 00h; store the final hex
mov bl, 1h ; goes in the power of 10
back3:
mov al, num[di]
sub al, 30h
mul bl
add cx, ax
mov al, bl
mov bl, 0ah
mul bl
mov bx, ax
dec di
dec dx
jnz back3

ret
aschex endp
end main

Microprocessor Page 2
For hex just make bx = 10h (divisor) in the display proc

;2. Write a program to find the sum of the following series up to the terms
specified by the user and display the result in
;decimal format. (also try to display the sum in Hex format)
;2 x 4 + 3 x 6 + ... to n terms
.model small
.stack 32
.data
str db "enter the number: $"
max db 4
len db ?
num db 4 dup('?')
sum dw 00
.code
main proc far
mov ax, @data
mov ds, ax

; display message
lea dx, str
mov ah, 09h
int 21h
; read n
mov ah, 0ah
lea dx, max
int 21h
;ascii to hex
call aschex ; cx ma hex aauxa

Microprocessor Page 3
call aschex ; cx ma hex aauxa

; caluclate

; 2((2*2)+ (3*3))
back:
mov al, cl
add al, 1h
mul al
add sum ,ax
add sum ,ax
loop back

; display
mov ah, 02h
; break line
mov dl, 0ah
int 21h
mov ax, sum
mov dx, 00h
call display
; terminate
mov ax, 4c00h
int 21h
main endp
display proc
; ax = value
mov cx, 00h
back2 :
mov dx, 00h
mov bx, 10
div bx ; dx = rem, ax = quotient
add dx, 30h; ascii to value
push dx
add cx, 1h
cmp ax, 00h
jne back2
mov ah, 02h
pooop:
pop dx
int 21h
loop pooop
ret
display endp
aschex proc
; LOGIC D0+D1*A+D2*A*A
mov dl, len
mov dh, 00h
mov di, dx
dec di ; max index
mov cx, 00h; store the final hex
mov bl, 1h ; goes in the power of 10
back3:
mov al, num[di]
sub al, 30h
mul bl
add cx, ax

Microprocessor Page 4
add cx, ax
mov al, bl
mov bl, 0ah
mul bl
mov bx, ax
dec di
dec dx
jnz back3

ret
aschex endp
end main

For hex just make bx = 10h (divisor) in the display proc

; 3. Write a program that takes a string and count the number of words in the
string. Display the count in decimal format
.model small
.stack 32
.data
max db 20
len db ?
str db 20 dup('?')
count dw 00
.code
main proc far
mov ax, @data
mov ds, ax
;read
mov ah, 0ah
lea dx, max

Microprocessor Page 5
lea dx, max
int 21h
; coutner
mov cl, len
mov ch, 00h
mov di, 00h

back:
mov al, str[di]
mov ah, str[di+1]
cmp al, ' '
jne skip
cmp ah, ' '
je skip
inc count
skip:
inc di
loop back
inc count
; display
; line break
mov dl, 0ah
mov ah, 02h
int 21h
mov dl, 0dh
int 21h
mov ax, count
call display
; terminate
mov ax, 4c00h
int 21h
main endp
display proc
; ax = value
mov cx, 00h
back2 :
mov dx, 00h
mov bx, 10
div bx ; dx = rem, ax = quotient
add dx, 30h; ascii to value
push dx
add cx, 1h
cmp ax, 00h
jne back2
mov ah, 02h
pooop:
pop dx
int 21h
loop pooop
ret
display endp
end main

Microprocessor Page 6
;4. Write a program that takes a string and count the no of vowels in the string.
Display the count in decimal format.

.model small
.stack 32
.data
maxchr db 50
len db ?
str db 50 dup('0')
vcount dw 00h
vowel db "aeiouAEIOU"
.code
main proc far
mov ax, @data
mov ds, ax
; read
mov ah, 0ah
lea dx, maxchr
int 21h
mov cl, len
mov ch, 00h
mov di, 00h
back:
mov al, str[di]
call vcounter
inc di

Microprocessor Page 7
inc di
loop back
; break line
call breakline
mov ax, vcount
call display

mov ah, 02
mov dl, 0dh
int 10h

; terminate
mov ax, 4c00h
int 21h
main endp
vcounter proc
; al = char
push cx
mov cx, 0ah
mov si, 0h
back1:
cmp al, vowel[si]
jne next1
inc vcount
pop cx
ret
next1:
inc si
loop back1
pop cx
ret
vcounter endp

display proc
; ax = value
mov cx, 00h
back2 :
mov dx, 00h
mov bx, 10
div bx ; dx = rem, ax = quotient
add dx, 30h; ascii to value
push dx
add cx, 1h
cmp ax, 00h
jne back2
mov ah, 02h
pooop:
pop dx
int 21h
loop pooop
ret
display endp
breakline proc
mov ah, 02h

Microprocessor Page 8
mov ah, 02h
mov dl, 0dh ; carriage return
int 21h
mov dl, 0ah ; line feed
int 21h
ret
breakline endp
end main

; 5. Write a program to add ten 16-bit numbers stored in memory and store and
display the result in decimal format.

.model small
.stack 32
.data
arr dw 1234,2,3,3,4,5,6,7,8,9
sum dw 00
.code
main proc far
mov ax, @data
mov ds, ax

mov cx, 0ah


mov di, 00h
back:
mov ax, arr[di]
add sum, ax
add di, 2h

Microprocessor Page 9
add di, 2h
loop back
mov ax, sum
call display

mov ax, 4c00h


int 21h
main endp
display proc
; ax = value
mov cx, 00h
back2 :
mov dx, 00h
mov bx, 10
div bx ; dx = rem, ax = quotient
add dx, 30h; ascii to value
push dx
add cx, 1h
cmp ax, 00h
jne back2
mov ah, 02h
pooop:
pop dx
int 21h
loop pooop
ret
display endp

end main

Discussion

Microprocessor Page 10
Discussion
During this lab, we got more familiarize with 8086 microprocessor. In lab we
solve the
Different miscellaneous problems such as calculating the sum of the series ,
reading input
Form the user, displaying the number in decimal as well as hexadecimal format and
more. This lab made us more flexible with the interrupt instruction of 8086.

Conclusion
This lab provided a hand on experience for assembly programming in 8086.

Microprocessor Page 11

You might also like