Sie sind auf Seite 1von 73

SDM INSTITUTE OF TECHNOLOGY

UJIRE-574 240

MICROPROCESSOR LAB MANUAL


8086

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 1


I) Programs involving
i) Data transfer instructions like:
ii] Byte and word data transfer in different addressing modes.
iii] Block move (with and without overlap)
iv] Block interchange
2) Arithmetic & logical operations like:
i] Addition and Subtraction of multi precision nos.
ii] Multiplication and Division of signed and unsigned Hexadecimal nos.
iii] ASCII adjustment instructions
iv] Code conversions
v] Arithmetic programs to find square cube, LCM, GCD, factorial, prime, Fibonacci
series

3) Bit manipulation instructions like checking:


i] Whether given data is positive or negative
ii] Whether given data is odd or even
iii] Logical 1’s and 0’s in a given data
iv] 2 out 5 code
v] Bit wise and nibble wise palindrome

4) Branch/Loop instructions like:


i] Arrays: addition/subtraction of N nos.
ii] Finding largest and smallest nos. Ascending and descending order
ii] Near and Far Conditional and Unconditional jumps, Calls and Returns

5) Programs on String manipulation like string transfer, string


reversing, searching for a string, etc.

6) Programs involving Software interrupts


Programs to use DOS interrupt INT 21h Function calls for
Reading a Character from keyboard, Buffered Keyboard input,
Display of character/ String on console

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 2


7) Experiments on interfacing 8086 with the following interfacing modules
through DIO (Digital Input/Output-PCI bus compatible) card
a) Matrix keyboard interfacing
b) Seven segment display interface
c) Logical controller interface
d) Stepper motor interface

8) Other Interfacing Programs


a) Interfacing a printer to an X86 microcomputer
b) PC to PC Communication

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 3


Micro Processor commands

-?

-u Converts machine code to assembly code

-g [start address] [break address]

-g 0100 0106

-t single step

-t2 2 steps execution

-a [starting address]

-a 0220

-u 0220

-c compares 2 areas in memory

-c 0200 L24 0400

e for keying in data into location

-e 0200 56 45 56

-d 0200 0202

-e 0203 "not me"

-d 0203 0210

-f fill command

-f 0110 L10 "hi"

-f 0110 0120 "hi"

-d 0110 0120

-p proceed

overflow direction interrupt sign zero Auxiliary parity Carry


carry
set OV DN EI NG ZR AC P CY
clear NV UP OI PL NZ NA PO NC

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 4


Steps to execute a program

1. startrun(type)cmd(click)OK

2. (Type)CD\ or CD.. twice

3. (If masm folder is inside C drive) (Type) CD masm

4.(Type) edit

5.(Type the program and save it.)FileSaveadd1.asm (You can choose any file name
to save it)

6.Fileexit

7.(Type) masm add1.asm; press enter(put semicolon or press enter key until you get
prompt)

Check that program is error free.If there is severe error or warning error ,it must be
corrected using (Type) editadd1.asm(please don’t give semicolon here)

8.(Type)Link add.obj; and press enter (put semicolon)

9.(Type) Debug add.exe and press enter.

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 5


; WAP TO ADD 2 8 BIT NUMBERS AND STORE THE RESULT IN THE MEMORY.

data segment
a db 13h
b db 24h
c db 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,a
add al,b
mov c,al
mov bl,00h
adc bl,00h
mov c+1,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 6


; WAP TO ADD N HEXADECIMAL NUMBER AND STORE THE RESULT IN THE MEMORY
data segment
a db 10 dup(13h)
c db 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cx,9
lea si,a
mov bl,00h
mov al,[si]
up:add al,[si+1]
adc bl,00h
inc si
loop up
mov c,al
mov c+1,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 7


; WAP TO ADD N DECIMAL NUMBER AND STORE THE RESULT IN THE MEMORY

data segment
a db 10 dup(99h)
c db 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cl,9
lea si,a
mov bl,00h
mov al,[si]
up:add al,[si+1]
daa
adc bl,00h
inc si
loop up
mov c,al
mov c+1,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 8


; WAP TO ADD 2 MULTIBYTE HEXADECIMAL NUMBER AND STORE THE RESULT IN
THE MEMORY
data segment
a dq 98765432abcd1234h
b dq 1111111111111111h
c dq 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov bx,0000h
mov cx,4
up:mov ax,word ptr a[bx]
adc ax,word ptr b[bx]
mov word ptr c[bx],ax
inc bx
inc bx
loop up
mov ax,0000h
adc ax,0000h
mov word ptr c[bx],ax
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 9


; WAP TO SUBTRACT 2 HEXADECIMAL NUMBERS AND STORE THE RESULT IN THE
MEMORY
data segment
a db 33h
b db 24h
c db ?
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,a
sub al,b
mov c,al
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 10


; WAP TO SUBTRACT 2 MULTIBYTE HEXADECIMAL NUMBER AND STORE THE
RESULT IN THE MEMORY
data segment
a dq 98765432abcd1234h
b dq 1111111111111111h
c dq ?
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov bx,0000h
mov cx,4
up:mov ax,word ptr a[bx]
sbb ax,word ptr b[bx]
mov word ptr c[bx],ax
inc bx
inc bx
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 11


;WAP TO MOVE A BLOCK OF DATA BYTE/WORD WITHOUT OVERLAPPING

data segment
dst db 5 dup(?)
src db 13h,14h,15h,26h,0ffh
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cl,5
lea si,src
lea di,dst
up:mov al,[si]
mov [di],al
inc si
inc di
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 12


;WAP TO MOVE A BLOCK OF DATA BYTE/WORD WITH OVERLAPPING
data segment
dst db 3 dup(?)
src db 13h,14h,15h,26h,0ffh
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cx,5
lea si,src
lea di,dst
up:mov al,[si]
mov [di],al
inc si
inc di
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 13


;WAP TO MOVE A BLOCK OF DATA BYTE/WORD IN THE REVERSE ORDER

data segment
src db 11h,12h,13h,14h,15h
len equ $-src
dst db len dup(0)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cx,len
lea si,src
lea di,dst+len-1
up:mov al,[si]
mov [di],al
inc si
dec di
loop up
int 3h
code ends
end start

;WAP TO EXCHANGE A BLOCK OF DATA BYTE/WORD STORED IN THE MEMORY LOCATION.

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 14


;WAP TO FIND LCM OF 2 8 BIT/16 BIT NUMBERS

data segment
n1 dw 000Fh
n2 dw 0005h
lcm dw 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov dx,0000h
mov ax,n1
mov bx,n2
back:push ax
push dx
div bx
cmp dx,0000h
je exit
pop dx
pop ax
add ax,n1
jnc next
inc dx
next:jmp back
exit:pop lcm+2
pop lcm
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 15


;WAP TO FIND GCD OF 2 8 BIT/16 BIT NUMBERS

data segment
n1 dw 21
n2 dw 5
gcd dw ?
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,n1
mov bx,n2
back:mov dx,0000h
div bx
cmp dx,0000h
je exit
mov ax,bx
mov bx,dx
jmp back
exit:mov gcd,bx
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 16


;WAP TO ARRANGE THE NUMBERS IN ASCENDING ORDER USING

BUBBLE SORT ALGORITHM


data segment
src db 0a0h,14h,90h,26h,0fh
len equ $-src
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov bx,len
dec bx
nxtrun:lea si,src
mov cx,bx
nxtcmp:mov al,[si]
cmp al,[si+1]
jc skip
xchg al,[si+1]
mov [si],al
skip:inc si
loop nxtcmp
dec bx
jnz nxtrun
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 17


;WAP TO FIND THE SMALLEST / LARGEST IN AN ARRAY

data segment
src db 0a0h,14h,90h,26h,0fh
len equ $-src
large db ?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov cx,len-1
lea si,src
mov al,[si]
up:cmp al,[si+1]
jnc skip
mov al,[si+1]
skip:inc si
loop up
mov large,al
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 18


;WAP TO FIND THE FACTORIAL OF A NUMBER
data segment
N dw 05h
fact dw 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ax,1
mov cx,N
cmp cx,0
je exit
up:mul cx
loop up
exit:mov fact+2,dx
mov fact,ax
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 19


;WAP TO MULTIPLY 2 UNSIGNED NUMBERS AND STORE THE RESULT IN THE MEMORY.(8 BIT/16
BIT/32 BIT)

data segment
a dd 0ffffffffh
b dd 0ffffffffh
c dd 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,word ptr[a]
mul word ptr[b]
mov word ptr[c],ax
mov word ptr[c+2],dx

mov ax,word ptr[a+2]


mul word ptr[b+2]
mov word ptr[c+4],ax
mov word ptr[c+6],dx

mov ax,word ptr[a]


mul word ptr[b+2]
add word ptr[c+2],ax
adc word ptr[c+4],dx
adc word ptr[c+6],00h

mov ax,word ptr[a+2]


mul word ptr[b]
add word ptr[c+2],ax
adc word ptr[c+4],dx
adc word ptr[c+6],00h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 20


data segment
a dd 0ffffffffh
c dd 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,word ptr[a]
mul word ptr[a]
mov word ptr[c],ax
mov word ptr[c+2],dx

mov ax,word ptr[a+2]


mul word ptr[a+2]
mov word ptr[c+4],ax
mov word ptr[c+6],dx

mov ax,word ptr[a]


mul word ptr[a+2]
add word ptr[c+2],ax
adc word ptr[c+4],dx
adc word ptr[c+6],00h

mov ax,word ptr[a+2]


mul word ptr[a]
add word ptr[c+2],ax
adc word ptr[c+4],dx
adc word ptr[c+6],00h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 21


;WAP TO FIND THE CUBE OF 16 BIT NUMBER

data segment
a dw 0ffffh
c dw 3 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,a
mul a
mov bx,ax
mov cx,dx
mul a
mov c,ax
mov c+2,dx
mov ax,cx
mul a
add c+2,ax
adc c+4,dx
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 22


;WAP TO DISPLAY THE KEY PRESSED FROM KEYPAD ON MONITOR

data segment
pa equ 0de00h
pb equ 0de01h
pc equ 0de02h
ctr equ 0de03h
fire db 86h,0afh,0f9h,8eh
help db 8ch,0c7h,86h,89h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,80h
mov dx,ctr
out dx,al
mov cx,05h
next:lea si,fire
call flash
call delay
call delay
lea si,help
call flash
call delay
call delay
loop next
int 03h

flash proc near


push cx
push bx
mov cx,04h
l1:mov bl,08h
mov al,[si]
l2:rol al,1
mov dx,pb
out dx,al
push ax
mov dx,pc
mov al,0ffh
out dx,al
mov al,00h
out dx,al
pop ax
dec bl
jz next1
jmp l2
next1:inc si
loop l1
pop bx
pop cx
ret
flash endp

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 23


delay proc near
push cx
push bx
mov cx,0ffffh
up1:mov bx,0ffffh
up2:dec bx
jnz up2
loop up1
pop bx
pop cx
ret
delay endp

code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 24


;WAP TO ACCEPT 2 BCD NUMBERS FROM THE KEYBOARD AND ADD 2 NUMBERS DISPLAY THE RESULT
ON THE MONITOR

data segment
msg1 db 10,13,'Enter first number : $'
msg2 db 10,13,'Enter second number : $'
msg3 db 10,13,'Addition of 2 numbers : $'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ah,00h
add al,bl
aaa
add ax,3030h
mov bx,ax
lea dx,msg3
mov ah,09h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 25


;WAP TO SEARCH CHARACTER IN A STRING STORED IN MEMORY

disp macro msg


lea dx,msg
mov ah,09h
int 21h
endm
display macro
mov ah,02h
int 21h
endm

data segment
src db 'sdmit'
cnt equ $-src
msg1 db 'Found at location:$'
msg2 db 'Not found$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
mov al,'m'
mov cx,cnt
cld
repne scasb -- Two conditions for exit (ZF=1 or CX=0)
jz found -- ZF = 1
disp msg2 -- CX=0 & ZF =0
jmp last
found:disp msg1
mov al,cnt
sub al,cl
aam
add ax,3030h
mov bx,ax
mov dl,bh
display
mov dl,bl
display
last:int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 26


;WAP TO COUNT THE NUMBER OF POSITIVE AND NEGATIVE NUMBERS IN THE ARRAY

data segment
src db 13h,34h,12h,0ffh,80h,0a0h
cnt equ $-src
positive db 0h
negative db 0h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea si,src
mov cx,cnt
up: mov al,[si]
rol al,1
jc jneg
inc [positive]
jmp down
jneg:inc [negative]
down:inc si
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 27


;WAP TO SEARCH A KEY IN AN ARRAY STORED IN MEMORY

data segment
src db 13h,14h,15h,26h,0ffh
cnt equ $-src
element db 14h
msg1 db 10,13,'Element found$'
msg2 db 10,13,'Element not found$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cl,cnt
lea si,src
mov al,element
up:cmp al,[si]
jz found
inc si
loop up
found:lea dx,msg1
jmp last
nofound:lea dx,msg2
last:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 28


;WAP TO DISPLAY CURRENT TIME ON MONITOR

data segment
msg db 'Current time is$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov ah,2ch
int 21h
mov al,ch
call disp
mov dl,':'
mov ah,02h
int 21h
mov al,cl
call disp
int 3h
disp proc near
aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
ret
disp endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 29


;WAP TO REVERSE THE STRING ENTERED FROM THE KEYBOARD
data segment
src db 'sdmit'
cnt equ $-src
nxt db '$'
dis db 10,13,'Entered string is:$'
disp db 10,13,'Reversed string is:'
dst db cnt dup(?),'$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea dx,dis
mov ah,09h
int 21h
lea dx,src
mov ah,09h
int 21h
lea si,src
lea di,dst+cnt-1
mov cx,cnt
up:cld
lodsb
std
stosb
loop up
lea dx,disp
mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 30


;WAP TO CHECK IF THE NUMBER IS 2 OUT OF 5 CODE
data segment
a db 05h
yes db 10,13,'Valid two out of five code$'
no db 10,13,'Not a valid two out of five code$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,a
and al,0e0h
jnz notwo
mov al,a
mov cx,5
up:ror al,1
jnc skip
inc bl
skip:loop up
cmp bl,02h
jnz notwo
lea dx,yes
jmp last
notwo:lea dx,no
last:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 31


; WAP TO ACCEPT 2 BCD NUMBERS FROM THE KEYBOARD AND SUBTRACT 2 NUMBERS DISPLAY THE
RESULT ON THE MONITOR
data segment
msg1 db 10,13,'Enter first number : $'
msg2 db 10,13,'Enter second number : $'
msg3 db 10,13,'Subtraction of 2 numbers : $'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
lea dx,msg3
mov ah,09h
int 21h
xchg al,bl
sub al,bl
aas
mov bl,al
jnc down
mov dl,'-'
mov ah,02h
int 21h
mov al,10
sub al,bl
mov bl,al
down:add bl,30h
mov dl,bl
mov ah,02h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 32


SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 33
;WAP TO ACCEPT 2 BCD NUMBERS FROM THE KEYBOARD AND MULTIPLY 2 NUMBERS DISPLAY THE
RESULT ON THE MONITOR
data segment
msg1 db 10,13,'Enter first number : $'
msg2 db 10,13,'Enter second number : $'
msg3 db 10,13,'Multiplication of 2 numbers : $'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mov bl,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mul bl
aam
add ax,3030h
mov bx,ax
lea dx,msg3
mov ah,09h
int 21h
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 34


; WAP TO ACCEPT 2 BCD NUMBERS FROM THE KEYBOARD AND DIVIDE 2 NUMBERS DISPLAY THE
RESULT ON THE MONITOR
key macro
mov ah,01h
int 21h
endm

disp macro
mov ah,02h
int 21h
endm

display macro msg


lea dx,msg
mov ah,09h
int 21h
endm

data segment
msg1 db 10,13,'Enter dividend : $'
msg2 db 10,13,'Enter divisor : $'
msg3 db 10,13,'Quotient : $'
msg4 db 10,13,'Remainder:$'
data ends

code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
display msg1
key
sub al,30h
mov bh,al
key
sub al,30h
mov bl,al
display msg2
key
sub al,30h
mov cl,al
mov ax,bx
aad
div cl
add ax,3030h
mov bx,ax
display msg3
mov dl,bl
disp
display msg4
mov dl,bh
disp
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 35


SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 36
;WAP TO MOVE A STRING FROM ONE LOCATION TO ANOTHER
data segment
src db 'sdmit$'
cnt equ $-src
disp db 10,13,'Transfered string is:'
dst db cnt dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
lea di,dst
mov cx,cnt
cld
rep movsb
lea dx,disp
mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 37


; WAP TO COUNT THE ODD AND EVEN NUMBERS
data segment
src db 13h,34h,12h,0ffh,80h,0a0h
cnt equ $-src
even1 db 0h
odd1 db 0h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea si,src
mov cx,cnt
up: mov al,[si]
ror al,1
jc jodd
inc [even1]
jmp down
jodd:inc [odd1]
down:inc si
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 38


; WAP TO CHECK IF THE ENTERED STRING IS PALINDROME OR NOT.
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
data segment
src db 'sdmit'
cnt equ $-src
dst db cnt dup(?)
msg1 db 'Entered string is palindrome$'
msg2 db 'Entered string is not a palindrome$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
lea di,dst+cnt-1
mov cx,cnt
up:cld
lodsb
std
stosb
loop up
mov cx,cnt
cld
lea si,src
lea di,dst
repe cmpsb
jnz nopal
disp msg1
jmp last
nopal:disp msg2
last:int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 39


;WAP TO COUNT THE NUMBER OF 1S AND 0S IN A NUMBER

data segment
N db 13h
ones db 0h
zeros db 0h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cx,08h
mov al,N
up:rol al,1
jc jone
inc [zeros]
jmp down
jone:inc [ones]
down:inc si
loop up
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 40


; WAP TO CHECK IF THE NUMBER IS BITWISE PALINDROME OR NOT
data segment
a db 81h
yes db 10,13,'Entered number is bitwise palindrome$'
no db 10,13,'Entered number is not bitwise palindrome$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,a
mov bl,00h
mov cx,08h
up: ror al,1
rcl bl,1
loop up
cmp al,bl
jz down
lea dx,no
jmp last
down:lea dx,yes
last:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 41


; WAP TO CHECK IF THE NUMBER IS EVEN OR ODD

data segment
N db 98h
msg1 db 10,13,'Entered number is even$'
msg2 db 10,13,'Entered number is odd$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,N
ror al,1
jc jodd
mov dx,offset msg1
jmp last
jodd:mov dx,offset msg2
last:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 42


; WAP TO COMPARE 2 STRINGS
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
data segment
src db 'sdmit'
cnt1 equ $-src
dst db 'sdmit'
cnt2 equ $-dst
msg1 db 'Entered strings are equal$'
msg2 db 'Entered string are not equal$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
mov cx,cnt1
mov bx,cnt2
cmp cx,bx
jnz noequal
lea si,src
lea di,dst
up:cld
repe cmpsb
jnz noequal
disp msg1
jmp last
noequal:disp msg2
last:int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 43


;WAP TO CHECK WHETHER THE GIVEN NUMBER IS POSITIVE OR NEGATIVE

data segment
N db 98h
msg1 db 10,13,'Entered number is positive$'
msg2 db 10,13,'Entered number is negative$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,N
rol al,1
jc jneg
mov dx,offset msg1
jmp last
jneg:mov dx,offset msg2
last:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 44


;WAP TO MULTIPLY 2 BYTES OF DATA AND STORE IN MEMORY.
data segment
a db 87h
b db 67h
c db 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,a
mul b
mov c,al
mov c+1,ah
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 45


;WAP TO MULTIPLY 2 BYTES OF DATA AND STORE IN MEMORY.

data segment
a dw 0ffffh
b dw 0067h
c dw 2 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ax,a
mul b
mov c,ax
mov c+2,dx
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 46


; WAP TO CONVERT HEXADECIMAL NUMBER TO DECIMAL NUMBER
data segment
N db 0ffh
res db 3 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,N
lea si,res+2
mov bl,10
call conv
mov bl,10
call conv
mov [si],al
mov cx,03h
lea si,res
up:mov dl,[si]
add dl,30h
mov ah,02h
int 21h
inc si
loop up
int 3h
conv proc near
mov ah,00h
div bl
mov [si],ah
dec si
ret
conv endp

code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 47


;WAP TO CONVERT DECIMAL TO HEXA DECIMAL
;ENTER A DECIMAL NUMBER IN THE RANGE 000 TO 255

data segment
res db ?
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov cx,03h
mov dl,10
mov bl,00h
up:mov ah,01h
int 21h
sub al,30h
push ax
mov al,bl
mul dl
mov bl,al
pop ax
add bl,al
loop up
mov res,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 48


;WAP TO INTERFACE KEYPAD TO MICROPROCESSOR AND DISPLAY THE KEY
PRESSED ON MONITOR
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm

data segment
pa equ 0de00h
pb equ 0de01h
pc equ 0de02h
ctr equ 0de03h
key db 10,13,'Entered key is:$'
data ends

code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,90h
mov dx,ctr
out dx,al
begin:mov al,80h
mov ch,0
mov bl,3
nxtrow:rol al,1
mov bh,al
mov dx,pc
out dx,al
mov cl,8
mov dx,pa
in al,dx
nxtcol:ror al,1
jc display
inc ch
dec cl
jnz nxtcol
mov al,bh
dec bl
jnz nxtrow
jmp begin
display:disp key
mov dl,ch
cmp dl,0ah
jc digit
add dl,07h
digit:add dl,30h
mov ah,02h
int 21h
int 03h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 49


data segment
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,8Ah
mov dx,0de03h
out dx,al
mov dx,0de01h
in al,dx
mov dx,0de00h
out dx,al
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 50


;WAP TO INTERFACE STEPPER MOTOR AND ROTATE IN BOTH THE DIRECTIONS
code segment
assume cs:code
start:mov al,8Ah
mov dx,0de03h
out dx,al
mov al,0ffh
up:inc al
mov dx,0de00h
out dx,al
call delay
cmp al,0fh
jnz up
int 3h

delay proc near


push ax
mov cx,0ffffh
l1:mov bx,0ffffh
l2:dec bx
jnz l2
loop l1
pop ax
ret
delay endp

code ends
end start

; WAP TO GENERATE/DISPLAY PRIME NUMBERS IN THE RANGE 1 TO N


data segment
no db 99
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ah,00h
mov al,02h
call disp
mov ax,0003h
up:mov ah,00h
mov cl,al
shr cl,01h
mov bl,02h
mov dx,ax
up1: mov ax,dx
div bl
cmp ah,00h
jz skip
inc bl
loop up1
mov ax,dx

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 51


call disp
skip:mov al,dl
add al,02h
cmp al,no
jc up
int 3h

disp proc near


push ax
push bx
push cx
push dx

aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,10
mov ah,02h
int 21h

mov dl,13
mov ah,02h
int 21h

pop dx
pop cx
pop bx
pop ax
ret
disp endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 52


data segment
pa equ 0de00h
pb equ 0de01h
pc equ 0de02h
ctr equ 0de03h
help db 0ffh,0c7h,86h,89h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,80h
mov dx,ctr
out dx,al
u1:mov cx,04h
lea si,help
up:mov al,[si]
call flash
call delay
inc si
loop up
jmp u1
int 03h

flash proc near


push cx
push bx

mov bl,08h
l2:rol al,1
mov dx,pb
out dx,al
push ax
mov dx,pc
mov al,0ffh
out dx,al
mov al,00h
out dx,al
pop ax
dec bl
jnz l2
pop bx
pop cx
ret
flash endp

delay proc near


push cx
push bx
mov cx,07fffh
up1:mov bx,0ffffh
up2:dec bx
jnz up2
loop up1
pop bx

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 53


pop cx
ret
delay endp
code ends
end start

code segment
assume cs:code
start:mov dx,0de03h
mov al,80h
out dx,al
mov cx,0100h
mov dx,0de02h
mov al,88h
l1:out dx,al
call delay
ror al,1
loop l1
int 3h
delay proc near
push cx
mov cx,0fffh
l2:mov bx,7777h
l3:dec bx
jnz l3
loop l2
pop cx
ret
delay endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 54


data segment
disp db 10,13,'Enter the string:$'
key db 10,13,'Enter character to be searched: $'
msg1 db 10,13,'Entered character is not found$'
msg2 db 10,13,'Entered character is found$'
src db 20 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
mov cx,00h
lea dx,disp
mov ah,09h
int 21h
up: mov ah,01h
int 21h
cmp al,13
je out1
mov [si],al
inc si
inc cx
jmp up
out1: inc si
mov al,'$'
mov [si],al
lea dx,key
mov ah,09h
int 21h
mov ah,01h
int 21h
cld
lea di,src
repne scasb
jz found
lea dx,msg1
jmp down
found:lea dx,msg2
down:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 55


data segment
inp db 10,13,'Enter the string:$'
oup db 10,13,'Output string is:'
src db 10 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
mov cx,0
lea dx,inp
mov ah,09h
int 21h
up: mov ah,01h
int 21h
cmp al,13
jz out1
mov [si],al
inc si
inc cx
jmp up
out1:inc si
mov al,'$'
mov [si],al
lea si,src
lea di,src
cld
conv: lodsb
sub al,20h
stosb
loop conv
lea dx,oup
mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 56


;HEX to ASCII conversion
data segment
num db 99h
inp db 10,13,'Entered 2 digit number is:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,num
mov bl,al
and bl,0fh
mov cl,04h
ror al,cl

and al,0fh
add bl,30h
add al,30h
lea dx,inp
mov ah,09h
int 21h
mov dl,al
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 57


;ASCII to HEX conversion
data segment
num db 0FFh
inp db 10,13,'Entered 2 digit number is:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,num
mov bl,al
and bl,0fh
mov cl,04h
ror al,cl
and al,0fh
lea dx,inp
mov ah,09h
int 21h
call hasc
mov al,bl
call hasc
int 3h
hasc proc near
cmp al,0Ah
jc add30
add al,07h
add30:add al,30h
mov dl,al
mov ah,02h
int 21h
ret
hasc endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 58


data segment
res db ?
inp db 10,13,'Enter 2 digit number:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,inp
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bh,al
mov ah,01h
int 21h
mov bl,al
sub bx,3030h
mov al,bh
mov cl,04h
ror al,cl
or bl,al
mov res,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 59


;ASCII to HEX conversion
data segment
res db ?
inp db 10,13,'Enter 2 digit hexadecimal number:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,inp
mov ah,09h
int 21h
mov ah,01h
int 21h
call ashx
mov bh,al
mov ah,01h
int 21h
call ashx
mov bl,al
mov al,bh

mov cl,04h
ror al,cl
or al,bl
mov res,al
int 3h
ashx proc near
cmp al,3Ah
jc sub30
sub al,07h
sub30:sub al,30h
ret
ashx endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 60


INT 14h - Serial I/O

Instruction: int 14h


BIOS Operation: Access the serial communications port
Parameters: ax, dx
The IBM BIOS supports up to four different serial communications ports (the
hardware supports up to eight). In general, most PCs have one or two serial
ports (COM1: and COM2:) installed. Int 14h supports four subfunctions-
initialize, transmit a character, receive a character, and status. For all
four services, the serial port number (a value in the range 0..3) is in the
dx register (0=COM1:, 1=COM2:, etc.). Int 14h expects and returns other
data in the al or ax register.

AH=0: Serial Port Initialization

Subfunction zero initializes a serial port. This call lets you set the baud
rate, select parity modes, select the number of stop bits, and the number
of bits transmitted over the serial line. These parameters are all
specified by the value in the al register using the following bit
encodings:
Bits Function
5..7 Select baud rate
000- 110 baud
001- 150
010- 300
011- 600
100- 1200
101- 2400
110- 4800
111- 9600

3..4 Select parity


00- No parity
01- Odd parity
10- No parity
11- Even parity

2 Stop bits
0-One stop bit
1-Two stop bits
0..1 Character Size
10- 7 bits
11- 8 bits
Although the standard PC serial port hardware supports 19,200 baud, some
BIOSes may not support this speed.

Example: Initialize COM1: to 2400 baud, no parity, eight bit data, and two
stop bits-
mov ah, 0 ;Initialize opcode
mov al, 10100111b ;Parameter data.
mov dx, 0 ;COM1: port.
int 14h
After the call to the initialization code, the serial port status is
returned in ax (see Serial Port Status, ah=3, below).

AH=1: Transmit a Character to the Serial Port

This function transmits the character in the al register through the serial
port specified in the dx register. On return, if ah contains zero, then the
character was transmitted properly. If bit 7 of ah contains one, upon
return, then some sort of error occurred. The remaining seven bits contain

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 61


all the error statuses returned by the GetStatus call except time out error
(which is returned in bit seven). If an error is reported, you should use
subfunction three to get the actual error values from the serial port
hardware.

Example: Transmit a character through the COM1: port


mov dx, 0 ;Select COM1:
mov al, 'a' ;Character to transmit
mov ah, 1 ;Transmit opcode
int 14h
test ah, 80h ;Check for error
jnz SerialError
This function will wait until the serial port finishes transmitting the
last character (if any) and then it will store the character into the
transmit register.

AH=2: Receive a Character from the Serial Port

Subfunction two is used to read a character from the serial port. On entry,
dx contains the serial port number. On exit, al contains the character read
from the serial port and bit seven of ah contains the error status. When
this routine is called, it does not return to the caller until a character
is received at the serial port.

Example: Reading a character from the COM1: port


mov dx, 0 ;Select COM1:
mov ah, 2 ;Receive opcode
int 14h
test ah, 80h ;Check for error
jnz SerialError

<Received character is now in AL>

AH=3: Serial Port Status

This call returns status information about the serial port including
whether or not an error has occurred, if a character has been received in
the receive buffer, if the transmit buffer is empty, and other pieces of
useful information. On entry into this routine, the dx register contains
the serial port number. On exit, the ax register contains the following
values:
AX: Bit Meaning
15 Time out error
14 Transmitter shift register empty
13 Transmitter holding register empty
12 Break detection error
11 Framing error
10 Parity error
9 Overrun error
8 Data available
7 Receive line signal detect
6 Ring indicator
5 Data set ready (DSR)
4 Clear to send (CTS)
3 Delta receive line signal detect
2 Trailing edge ring detector
1 Delta data set ready
0 Delta clear to send
There are a couple of useful bits, not pertaining to errors, returned in
this status information. If the data available bit is set (bit #8), then
the serial port has received data and you should read it from the serial

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 62


port. The Transmitter holding register empty bit (bit #13) tells you if the
transmit operation will be delayed while waiting for the current character
to be transmitted or if the next character will be immediately transmitted.
By testing these two bits, you can perform other operations while waiting
for the transmit register to become available or for the receive register
to contain a character.

If you're interested in serial communications, you should obtain a copy of


Joe Campbell's C Programmer's Guide to Serial Communications. Although
written specifically for C programmers, this book contains a lot of
information useful to programmers working in any programming language. See
the bibliography for more details.

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 63


TRANSMITTER PROGRAM

data segment
str db 'SDMIT$'
len equ $-str
disp1 db 'Data transmited successfully$'
disp2 db 'Error occured$'
data ends

code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea si,str
mov cx,len
mov ah,00h; initializaton
mov al,0e3h
mov dx,00h
int 14h

l1: mov ah,03h ;check status


mov dx,00h
int 14h

and ah,20h
cmp ah,20h
jne l1

mov al,[si]
inc si
;mov al,'a'
mov ah,01h ;transmit
mov dx,00h
int 14h
loop l1
test ah, 80h ;Check for error
jnz SerialError
mov dx,offset disp1
jmp last
serialerror:mov dx,offset disp2
last:mov ah,09h
int 21h

int 3h
code ends
end start
RECEIVER PROGRAM

data segment
data ends
code segment
assume cs:code,ds:data
start:mov ax,ds
mov ds,ax
mov ah,00h; initializaton
mov al,0e3h
mov dx,00h
int 14h

l1: mov ah,03h ;check status

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 64


mov dx,00h
int 14h

and ah,01h ;check 8th bit; if data available


cmp ah,01h
jne l1

mov ah,02h ;receive


mov dx,00h
int 14h
cmp al, '$'
je exit
mov dl,al ;display it to monitor
mov ah,02h
int 21h
jmp l1

exit: int 3h
code ends
end start

data segment
no db 99
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov ah,00h
mov al,02h
call disp
mov ax,0003h
up:mov ah,00h
mov cl,al
shr cl,01h
mov bl,02h
mov dx,ax
up1: mov ax,dx
div bl
cmp ah,00h
jz skip
inc bl
loop up1
mov ax,dx
call disp
skip:mov al,dl
add al,02h
cmp al,no
jc up
int 3h

disp proc near


push ax
push bx
push cx
push dx

aam

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 65


add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,10
mov ah,02h
int 21h

mov dl,13
mov ah,02h
int 21h

pop dx
pop cx
pop bx
pop ax
ret
disp endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 66


data segment
no db 55h
res db 50 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea si,res
mov ah,00h
mov al,02h
mov [si],al
mov ax,0003h
up:mov ah,00h
mov cl,al
shr cl,01h
mov bl,02h
mov dx,ax
up1: mov ax,dx
div bl
cmp ah,00h
jz skip
inc bl
loop up1
mov ax,dx
inc si
mov [si],al
skip:mov al,dl
add al,02h
cmp al,no
jc up
int 3h

code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 67


data segment
disp db 10,13,'Enter the string:$'
key db 10,13,'Enter character to be searched: $'
msg1 db 10,13,'Entered character is not found$'
msg2 db 10,13,'Entered character is found$'
src db 20 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
mov cx,00h
lea dx,disp
mov ah,09h
int 21h
up: mov ah,01h
int 21h
cmp al,13
je out1
mov [si],al
inc si
inc cx
jmp up
out1: inc si
mov al,'$'
mov [si],al
lea dx,key
mov ah,09h
int 21h
mov ah,01h
int 21h
cld
lea di,src
repne scasb
jz found
lea dx,msg1
jmp down
found:lea dx,msg2
down:mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 68


data segment
inp db 10,13,'Enter the string:$'
oup db 10,13,'Output string is:'
src db 10 dup(?)
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov es,ax
lea si,src
mov cx,0
lea dx,inp
mov ah,09h
int 21h
up: mov ah,01h
int 21h
cmp al,13
jz out1
mov [si],al
inc si
inc cx
jmp up
out1:inc si
mov al,'$'
mov [si],al
lea si,src
lea di,src
cld
conv: lodsb
sub al,20h
stosb
loop conv
lea dx,oup
mov ah,09h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 69


;HEX to ASCII conversion
data segment
num db 99h
inp db 10,13,'Entered 2 digit number is:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,num
mov bl,al
and bl,0fh
mov cl,04h
ror al,cl

and al,0fh
add bl,30h
add al,30h
lea dx,inp
mov ah,09h
int 21h
mov dl,al
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 70


;ASCII to HEX conversion
data segment
num db 0FFh
inp db 10,13,'Entered 2 digit number is:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
mov al,num
mov bl,al
and bl,0fh
mov cl,04h
ror al,cl
and al,0fh
lea dx,inp
mov ah,09h
int 21h
call hasc
mov al,bl
call hasc
int 3h
hasc proc near
cmp al,0Ah
jc add30
add al,07h
add30:add al,30h
mov dl,al
mov ah,02h
int 21h
ret
hasc endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 71


;ASCII to DECIMAL conversion
data segment
res db ?
inp db 10,13,'Enter 2 digit number:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,inp
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bh,al
mov ah,01h
int 21h
mov bl,al
sub bx,3030h
mov al,bh
mov cl,04h
ror al,cl
or bl,al
mov res,bl
int 3h
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 72


;ASCII to HEX conversion
data segment
res db ?
inp db 10,13,'Enter 2 digit hexadecimal number:$'
data ends
code segment
assume cs:code,ds:data
start:mov ax,data
mov ds,ax
lea dx,inp
mov ah,09h
int 21h
mov ah,01h
int 21h
call ashx
mov bh,al
mov ah,01h
int 21h
call ashx
mov bl,al
mov al,bh
mov cl,04h
ror al,cl
or al,bl
mov res,al
int 3h
ashx proc near
cmp al,3Ah
jc sub30
sub al,07h
sub30:sub al,30h
ret
ashx endp
code ends
end start

SDMIT, E&C DEPT MICROPROCESSOR LAB MANUAL Page 73

Das könnte Ihnen auch gefallen