Вы находитесь на странице: 1из 16

Microprocessor & Interfacing

(8086 family microprocessors)

Jimmy Mathew
Asst. Professor Sr.,
School of Computing Science & Engineering (SCSE),
VIT University, Vellore, India
Email: jimmym@vit.ac.in / Room: SJT 313 A08
Practice Programs

MP & I/F Module 2 JMW VIT-U 2


Practice programs

Use the following suitable program constructs in your
programs (with REP, LOOP, JMP):


If Then Else


For loop


While loop


Do While loop


Switch case


Repeat Until

MP & I/F Module 2 JMW VIT-U 3


Practice programs

ALP to find average of numbers in an array:
SIZE EQU 05h
JMP HERE
num1 db 02h, 10h, 22h, 01h, 0Ah
HERE:
MOV CX, SIZE
LEA SI, num1
MOV AL, [SI]
DEC CX

NEXT: INC SI
MOV BL, [SI]
ADD AL, BL
LOOP NEXT

DIV AL, SIZE

MOV SI, 2000h


MOV [SI], AL

MP & I/F Module 2 JMW VIT-U 4


Practice programs
ALP to reverse the numbers in an array to another array:
JMP HERE
num1 db 02h, 10h, 22h, 01h, 0Ah
num2 db 5 DUP (?)
HERE:
MOV CX, 05h
LEA SI, num1
LEA DI, num2
ADD SI, 04h
NEXT:
MOV AL, [SI]
MOV [DI], AL
DEC SI
INC DI
LOOP NEXT

MP & I/F Module 2 JMW VIT-U 5


Practice programs
ALP to find a given number is even or odd (Method 1):
JMP HERE
num1 db 02h
HERE:
MOV AL, num
DIV 02h
CMP AH, 00H
JNE ODD
;PRINT “EVEN NUMBER”
ODD: ;PRINT “ODD NUMBER”
HLT

MP & I/F Module 2 JMW VIT-U 6


Practice programs
ALP to find a given number is even or odd (Method 2):
JMP HERE
num1 db 02h
HERE:
MOV AL, num
AND AL, 01H
CMP AL, 00H
JG ODD
;PRINT “EVEN NUMBER”
ODD: ;PRINT “ODD NUMBER”
HLT

MP & I/F Module 2 JMW VIT-U 7


Practice programs
ALP to store given numbers in even or odd arrays:
JMP HERE
num_arr db 09h, 34h, 12h, 03h, 11h
even_arr db ?
odd_arr db ?
HERE: LEA BP, num_arr
MOV CX, LENGTH num_arr
MOV BH, 02h
NEXT: MOV AL, [BP]
MOV BL, AL
DIV BH
CMP AH, 00h
JNE ODD
LEA SI, even_arr
MOV [SI], BL
INC SI
JMP AGAIN
ODD: LEA DI, odd_arr
MOV [DI], BL
INC DI
AGAIN: INC BP
LOOP NEXT
HLT
MP & I/F Module 2 JMW VIT-U 8
Practice programs
ALP to search a character in a string (Method 1):
JMP HERE
string1 db 'Hello'
key db 'e'

HERE: LEA SI, string1


MOV CX, LENGTH string1
MOV AH, key
NEXT: MOV AL, [SI]
CMP AL, AH
JE FOUND
INC SI
LOOP NEXT
FOUND: ;PRINT “Character is present”
HLT

MP & I/F Module 2 JMW VIT-U 9


Practice programs
ALP to search a character in a string (Method 2):
JMP HERE
string1 db 'Hello'
key db 'e'

HERE: MOV AX, seg string1


MOV ES, AX
MOV DI, OFFSET string1
MOV CX, 0005h
LEA SI, key
MOV AX, [SI]
CLD
REPNE SCASW
JZ NOMATCH
;PRINT “Character is present”
NOMATCH:
;PRINT “Not found”
HLT

MP & I/F Module 2 JMW VIT-U 10


Practice programs
ALP to compare two strings (Method 1):
JMP HERE
string1 db 'Hello'
string2 db 'world'

HERE: LEA SI, string1


LEA DI, string2
MOV CX, 0005h
NEXT: MOV AL, [SI]
MOV AH, [DI]
CMP AL, AH
JNE NOMATCH
INC SI
INC DI
LOOP NEXT
;PRINT “Strings are matching”
NOMATCH:
;PRINT ”No match found”
HLT

MP & I/F Module 2 JMW VIT-U 11


Practice programs
ALP to compare two strings (Method 2):
JMP HERE
string1 db 'Hello'
string2 db 'world'

HERE: MOV AX, seg string1


MOV DS, AX
MOV AX, seg string2
MOV ES, AX
MOV SI, OFFSET string1
MOV DI, OFFSET string2
MOV CX, 0005h
CLD
REPE CMPSW
JNE NOMATCH
;PRINT “Character is present”
NOMATCH:
;PRINT “Not found”
HLT

MP & I/F Module 2 JMW VIT-U 12


Practice programs
ALP to simulate a room temperature controller:
AGAIN: IN AL, 0Ah ;read temp sensor input at port 0Ah
CMP AL, 018h ;check for 24'C
JG OFFHEATER
IN AL, 0Bh ;read current output port status at 0Bh
OR AL, 010h ;modify port to HEATER ON (bit no. 5)
OUT 0Bh, AL ;send control to port
JMP AGAIN
OFFHEATER:
IN AL, 0Bh ;read current output port status at 0Bh
AND AL, 0EFh ;modify port to HEATER OFF (pin no. 5)
OUT 0Bh, AL ;send control to port
JMP AGAIN
HLT

MP & I/F Module 2 JMW VIT-U 13


Practice programs
ALP to simulate a room lights controller:
AGAIN: IN AL, 0Ah ;read room switch status at port 0Ah
AND AL, 02h ;test if Sw1 is on (pin no. 2)
JZ SW1OFF
IN AL, 0Bh ;read current output port status at 0Bh
OR AL, 02h ;switch on Light 1 (pin no. 2)
OUT 0Bh, AL ;send control to output port at 0Bh
NEXT IN AL, 0Ah
AND AL, 010h ;test if Sw2 is on (pin no. 5)
JZ SW2OFF
IN AL, 0Bh
OR AL, 010h ;switch on Light 2 (pin no. 5)
OUT 0Bh, AL
JMP AGAIN
SW1OFF: IN AL, 0Bh
AND AL, 0FDh ;switch off Light 1 (pin no. 2)
OUT 0Bh, AL
JMP NEXT
SW2OFF: IN AL, 0Bh
AND AL, 0EFh ;switch off Light 2 (pin no. 5)
OUT 0Bh, AL
JMP MP
AGAIN
& I/F
HLT Module 2 JMW VIT-U 14
Practice programs
Write an ALP to store the contents of an array into the location
2400:2000h.
JMP HERE
arr db 02h,04,03h,04h mov bp, si
HERE: mov si, offset arr mov dx, di
mov bp, si push dx
mov dx, 02000h loop label
push dx
mov cx,04h HLT
label:
mov dx,seg arr
mov ds, dx
mov si, bp
mov al,[si]
mov dx, 02400h
mov ds, dx
pop dx
mov di, dx
mov [di],al
inc si
inc di MP & I/F Module 2 JMW VIT-U 15
Practice programs

ALP to simulate operations of a calculator (+ - * /)


ALP to check vowels in a given string


ALP to check a given year is leap year or not


ALP to reverse a number


ALP to check if a given string is palindrome


ALP to remove spaces in a given string

MP & I/F Module 2 JMW VIT-U 16

Вам также может понравиться