0% found this document useful (0 votes)
29 views13 pages

Mnemonics for Microcontroller Programs

The document contains assembly language programs for microprocessors and microcontrollers. It includes programs to add, subtract, multiply and divide numbers, programs to generate even and odd numbers, programs for traffic light control, and a program to interface with an LCD display.

Uploaded by

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

Mnemonics for Microcontroller Programs

The document contains assembly language programs for microprocessors and microcontrollers. It includes programs to add, subtract, multiply and divide numbers, programs to generate even and odd numbers, programs for traffic light control, and a program to interface with an LCD display.

Uploaded by

Memona Memon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MICROCONTROLLER & EMBADED SYSTEM

Q1. Write a assembly program for microprocessor that add two


numbers “03 H and 04 H”?
MNEMONICS
MVI A, 03 H
MVI B, 04 H
ADD B
HLT

Q2. Write a assembly program for microprocessor that add three


numbers “05 H , 03 H and 06 H”?
MNEMONICS
MVI A, 05 H
MVI B, 03 H
MVI C, 06 H
ADD B
ADD C
HLT
Q3. Write a assembly program for microcontroller that add three
numbers “05 H , 03 H and 06 H”?
MNEMONICS
ORG
MOV A, # 05
MOV R₀, # 03
MOV R₁, # 06
ADD A, R₀
ADD A, R₁
END

1
MICROCONTROLLER & EMBADED SYSTEM

Q4. Write a program to move a byte from memory location “1703” to


“1507”?

MNEMONICS

LD A, 1703
ST A, 1507
HLT

Q5. Write a program which add five numbers at addresses “1601 to


1605” and save the result at address “1606” by making increment in
low byte of HL pair?

MNEMONICS

ADDRESS DATA
MVI H, 16 ; High byte of M register
MVI L, 01 ; Low byte of M register 1601 02

MOV A, M 1602 05

INR L ; Increment in low byte 1603 07

ADD M 1604 0A
INR L 1605 03
ADD M ; -----After execution -----
INR L 1606 1B
ADD M
INR L
ADD M
INR L
MOV M, A
HLT

Q6. Write a program that exchange data between two registers?


2
MICROCONTROLLER & EMBADED SYSTEM

MNEMONICS

MVI A, 0A h
MVI B, O5 h
XCHG BC
HLT

Q7. Write a program which add five numbers at addresses “1501 to


1505” and save the result at address “1506” by making increment in HL
pair?

MNEMONICS

LXI H, 1507
MOV A, M
INX H
ADD M
INX H
ADD M
INX H
ADD M
INX H
ADD M
INX H
MOV M, A
HLT

Q8. Write a program that generates first ten even numbers in


microprocessor from memory location “1601” to “160A”?

3
MICROCONTROLLER & EMBADED SYSTEM

LABEL MNEMONICS
LXI H, 1601
MVI A, 02 h
MVI C, 0A h
next: MOV M, A
INX H
INR A
INR A
DCR C
JNZ next
HLT

Q9. Write a program that generates first ten odd numbers in


microprocessor from memory location “1601” to “160A”?

LABEL MNEMONICS
LXI H, 1601
MVI A, 01 h
MVI C, 0A h
next: MOV M, A
INX H
INR A
INR A
DCR C
JNZ next
HLT
Q10. Write the program that load from descending order i.e. from 170A
to 1701 and copy that data to 1401 to 140A?

LABEL MNEMONICS
4
MICROCONTROLLER & EMBADED SYSTEM

LXI H, 170A
LXI B, 1401
MVI D, 0A h
next: MOV A, M
STAX B
DCX H
INX B
DCR D
JNZ next

Q11. Write a assembly program for microprocessor that add five


numbers “02 H , 01 H , 03 H , 05 H , 0A H” stored at addresses “1501 to
1505” by generating loops?
LABEL MNEMONICS
LXI H, 1501
MVI C, 05 h
MOV A, M
Jump: INX H
ADD M
DCR C
JNZ Jump
HLT

Q12. Write the program for microprocessor that multiplies “5H” with
“5H”?
LABEL MNEMONICS
MVI A, 05 h

5
MICROCONTROLLER & EMBADED SYSTEM

MVI B, 05 h
MVI C, 04 h
Again: ADD B
DCR C
JNZ again
HLT
Q13. Write the program for microcontroller that multiplies “5H” with
“7H”?
LABEL MNEMONICS
ORG
MOV A, # 05
MOV R₀, # 06
again: ADD A, R₀
DJNZ R₀ again
END

Q14. Write the program for traffic light on main road shows green light
for 25 sec , yellow for 5 sec and red for 20 sec the bit number 1,2 and 3
of output port # 4 are the controlling bits for the peripheral show a
program that can produce time delay of 25 sec , 5 sec and 20 sec for
green yellow and red light respectively?

6
MICROCONTROLLER & EMBADED SYSTEM

LABEL MNEMONICS

Again: MVI A, 19 h
STA temp
MVI A, 02 h
OUT 04 h
LoopGr: CALL D1Sec ; 1 sec delay subroutine
LDA temp
DCR A
STA temp
JNZ LoopGr
MVI A, 05 h
STA temp
MVI A, 04 h
OUT 04 h
LoopYr: CALL D1Sec
LDA temp
DCR A
STA temp
JNZ LoopYr
MVI A, 14 h
STA temp
MVI A, 08 h
OUT 04 h
LoopRr: CALL D1Sec
LDA temp
DCR A
STA temp
JNZ LoopRr

7
MICROCONTROLLER & EMBADED SYSTEM

JMP Again
temp: 1600 ; Temporary storing on address

Q15. Write a program in assembly language for approximate 1 sec for


delay subroutine and also calculate its stats
(taking clock frequency approximately 3MHz)
LABEL MNEMONICS
MVI A, A h ; 7T
loop1: MVI B, 64 h ; 7T
loop2: MVI C, DC h ; 7T
loop3: DCR C ; 4T
JNZ loop3 ; 10 T & 7 T when C = 0
DCR B ; 4T
JNZ loop2 ; 10 T & 7 T when B = 0
DCR A ; 4T
JNZ loop1 ; 10 T & 7 T when A = 0
NOP ; 4T
RET ; 10 T
CALCULATION
( 7 + (10 x ( 7 + ( 100 x ( 7 + ( 220 x ( 4 + 10) – 3 ) + 4 + 10 ) – 3) + 4 + 10 ) + 4 + 10 ) T
= 3098201 T
1
Since frequency is 3MHz so 1 T = μ sec
3
Thus
3098201 T = 1.032733 sec ≈ 1 sec

Q16. Assume 5 BCD data items are stored in RAM location start from
40H to 44H develop a program to find the sum of all numbers in BCD
LABEL MNEMONICS
MOV R₀, # 40
MOV R₂, # 05

8
MICROCONTROLLER & EMBADED SYSTEM

CLA A
MOV R₇, A
again: ADD A, @R₀
DA A
JNC next
INC R₇
next: INC R₀
DJNZ R₂, again

Q17. Find sum of two numbers “07 H and 0A H” in BCD format


MNEMONICS
MVI A, 07 h
MVI B, 0A h
ADD B
DA A ; Decimal adjust
HLT
OR
LXI H, 1601
MOV A, M ADDRESS DATA
INX H 1601 07 Hex
ADD M
1602 0A Hex
DA A
-----After execution -----
INX H
1603 17 Dec
MOV M, A
HLT
Q18. Find sum of ten numbers at addresses “1401 to 140A” in
microprocessor and store result at location 140B in BCD format. Use
loops in program
LABEL MNEMONICS
LXI H, 1401

9
MICROCONTROLLER & EMBADED SYSTEM

MOV A, M
MVI C, 08 h
again: INX H
ADD M
DCR C
JNZ again
INX H
ADD M
DA A
INX H
MOV M, A
HLT

Q19. Write a program that compare larger of two from 1401 , 1402 and
store larger at 1403
LABEL MNEMONICS
LXI H, 1401
MOV A, M
INX H
CMP M
JNC jump
MOV A, M
jump: INX H
MOV M, A
HLT
Q20. Write a program that compare smaller of two from 1601 , 1602
and store larger at 1603
LABEL MNEMONICS
LXI H, 1601
MOV A, M

10
MICROCONTROLLER & EMBADED SYSTEM

INX H
CMP M
JNC check
JMP jump
check: MOV A, M
jump: INX H
MOV M, A
HLT

Q21. Write the program for 16x2 LCD interfacing with microcontroller.
Display latter ‘N’ on LCD. Assume P₁ ꓸ₀ to P₁ ꓸ₇ are connected with DB₀ to
DB₇, P₂ ꓸ₀ is connected with RS pin, P₂ ꓸ₁ is connected with R/W pin and
P₂ ꓸ₂ is connected with E (enable) pin of LCD.

MNEMONICS
ORG 00H
MOV A, # 38 h ; Use two lines and 5x7 matrix
A CALL CmndWrt
A CALL Delay

MOV A, # 0F h ; LCD ON, Cursor ON, Cursor blinking ON


A CALL CmndWrt
A CALL Delay

MOV A, # 01 h ; Clear screen


A CALL CmndWrt
A CALL Delay

MOV A, # 06 h ; Increment in cursor, shift cursor to right


A CALL CmndWrt

11
MICROCONTROLLER & EMBADED SYSTEM

A CALL Delay

MOV A, # 0E h ; Display ON, Cursor blinking OFF


A CALL CmndWrt
A CALL Delay

MOV A, # 80 h ; Force cursor to the beginning of the first line


A CALL CmndWrt
A CALL Delay

MOV A, # ‘N’ ; Data


A CALL DataWrt
A CALL Delay

CmndWrt:
MOV P₁, A
CLR P₂ ꓸ₀ ; RS=0 for Command
CLR P₂ ꓸ₁ ; R/W=0 for Write
SETB P₂ ꓸ₂ ; Enable
CLR P₂ ꓸ₂
RET

DataWrt:
MOV P₁, A
SETB P₂ ꓸ₀ ; RS=0 for Data
CLR P₂ ꓸ₁ ; R/W=0 for Write
SETB P₂ ꓸ₂ ; Enable
CLR P₂ ꓸ₂
RET

Delay:
12
MICROCONTROLLER & EMBADED SYSTEM

MOV R₃, # 50
MOV R₂, # 255
DJNZ R₃
DJNZ R₂
RET

13

You might also like