Assembly Language Programming lEC 13
Assembly Language Programming lEC 13
Language
Programming
Example: Addition of 5 numbers stored in
consecutive memory locations starting from 0050H
XRA A
MVI C,05H
LXI H,0050H
LOOP ADD M
INX H
DCR C
JNZ LOOP
MOV B,A
HLT
Example: Addition of 10 numbers stored in
consecutive memory locations starting from
0050H, store the summation result in memory
location 0100H and carry in 0101H
XRA A
MOV D,A
MVI C,0AH
LXI H,0050H
LOOP ADD M
JNC NEXT
INR D
NEXT INX H
DCR C
JNZ LOOP
STA 0100H
MOV A,D
STA 0101H
HLT
Example: Copy 10 numbers stored in memory
locations starting from 0030H to 0040H
LXI H,0030H
LXI D,0040H
MVI C,0AH
LOOP MOV A,M
STAX D
INX H
INX D
DCR C
JNZ LOOP
HLT
Example: Given N in memory location 0030H,
find the value of Y, where Y=1+2+3+…..+(N-1)+N.
Store the 8 bit Y value in memory location 0031H.
LXI H,0030H
MOV C,M
XRA A
LOOP ADD C
DCR C
JNZ LOOP
STA 0031H
HLT
Example: Given N in memory location 0030h,
find the value of Y,
where 𝒀 = 𝟏𝟐 + 𝟐𝟐 + 𝟑𝟐 + ⋯ . 𝑵 − 𝟏 𝟐 + 𝑵𝟐
Store the 8 bit Y value in memory location 0031H.
LXI H,0030H
MOV C,M
XRA A
LOOP2 MOV B,C
LOOP1 ADD C
DCR B
JNZ LOOP1
DCR C
JNZ LOOP2
STA 0031H
HLT
Example: Given N in memory location 002FH
find the average of N numbers stored in memory
locations starting from 0030H. Store the result in
memory location 0040H.
LXI H,002FH
MOV B,M
MOV C,B
XRA A
LOOP1 INX H
ADD M
DCR C
JNZ LOOP1
LOOP2 INR C
SUB B
JNC LOOP2
MOV A,C
STA 0040H
HLT
LXI SP,0092H
LXI H,0050H
MVI B,0AH
LOOP2 MOV D,H
Example: Arrange 10 numbers stored in MOV E,L
memory locations starting from 0050H MOV C,B
LOOP1 LDAX D
in descending order, the results are also CMP M
to be stored from the same starting JC HI
address. PUSH PSW
MOV A,M
STAX D
POP PSW
MOV M,A
HI INX D
DCR C
JNZ LOOP1
INX H
DCR B
JNZ LOOP2
HLT
Time Delay Subrouties
Time Delay using Register Pair
Time Delay using Loop within a Loop
Counter Design