8051 Basic Programs (Using Address)
8051 Basic Programs (Using Address)
1
PROGRAM TO ADD TWO 8-BIT DATA
2112 80 FE HALT: SJMP HALT Remain idle in infini te loo0. Program end.
address.
2100 ORG 2100H Specify program starting
; Load address of minuend in
2100 DPTR.
90 24 00 MOV DPTR,#2400H
2103 EO MOVX A, @DPTR ; Movethe minuend to A.
2104 F9 MOV R1,A Save the minuend in R1.
7 2105 A3 INC DPTR ;Increment DPTR to point subtrahend.
8 2106 EO MOVX A, @DPTR ;Load subtrahend in A.
9 2107 c9 XCH A, R1 Get mi nuend inand subtrahend in R1.
A
10 2108 78 00 MOV RO, #00H Clear R0 to account for sign.
11 210A C3 CLR C Clear carry.
12 210B 99 SUBB A, R1 Subtract R1 from A.
13
14 210C 50 03 JNC AHEAD ;Check carry fl ag, If carry is set then,.
15 210E F4 CPL A get 2's complement of result in A.
16 210F 04 INC A
17 2110 08 INC RO ;Set RO as one to indicate negative result.
18 2111
19 2111 A3 AHEAD: INC DPTR Increment DPTR.
20 2112 FO MOVX @DPTR,A ;Save magni tude of result in external memory.
CHAPTER8 AsSEMBLY LANGUAGE PRoGRAMMING 8. 81
2116 80 FE HALT: SIMP HALT Remain idle in infinite l0op. Program end
END ; ASsembly end.
118
Sample dato Memory address Content
Input Data Minuend AC 2400 4C
subtrahend = F7 2401
Output Data : Difference =
AB 2402 AB
8 2105 18 DEC RO
CHAPTER 8 AssEMBLY LANGUaGE ProGRAMMING 8. 89
2112 D8 F5 AHEAD: DINZ R0, AGAIN ;Decrement cournt and go to again if count is
not zero,otherwi se go to next instruction.
42 H 2402 1c
57 2403 42
H
2404 57 Array
13 2405 13
FEN 2406 FE
Output Data FE 2500 FE Largest data
Sample data
Me
a dmory
dres Content
ontent Memory Content
address address
Input Data: 07 2400 07 output data :07 2400 07
AB 2401 AB 34 2401 34
92 2402 92 4F 2402 4F
84 2403 84 69 2403 69
4F 2404 4F 84 2404 84
69 2405 69 92 2405 92
F2 2406 F2 AB 2406 AB
34 2407 34 F2 2407 F2
(Before sorting) CAfter sorting)