Manual 06
Manual 06
Name: __________________________________________________________
Section: _________________________________________________________
OBJECTIVE
1. To be able to write ALP for arranging numbers in ascending /descending order stored in external
memory locations.
2. To understand how to access data from external memory and use of branch instructions.
THEORY
69
memory at the address indicated by DPTR.
MOVX instruction
MOVX is a widely used instruction allowing access to external data memory space. To bring
externally stored data into the CPU, we use the instruction “MOVX A, @DPTR”. This instruction
will read the byte of data pointed to by register DPTR and store it in the accumulator
PROCEDURE
Write Program
1. Start Keil by double clicking on Keil icon.
2. Create a new project.
3. Select device for Target.
4. Double click on ATMEL or INTEL and select 80c51AH 0r AT89C51.
5. Type the program in text editor and save as .asm or .a51.
Compile the Program
6. Right click on source group and build the target.
7. Check for any errors in the output window and remove if any.
Run, Debug the Program
8. Click on Debug and start simulation and start/stop debug session.
9. Run the program step by step.
10. Observe the output on the project window. It will display all internal registers of
8051 and their contents.
11. Note down the values of external memory location 3000H in the observation table.
SAMPLE PROGRAM 1: Write ALP for arranging five numbers in ascending order
stored in external memory location 3000H.
Step 1-Algorithm
1. Initialize comparison or pass counter
2. Initialize memory pointer to read number from array
3. Initialize byte counter
4. Read numbers from the array
5. Compare two numbers.
6. If number <=next number, then go to step 9.
7. Interchange or swap numbers.
8. Increment memory pointer to read next number from array.
9. Decrement byte counter by one.
10. If word counter is not equal to zero, then go to step 2.
11. Stop
70
Step 2-Flow Chart
71
Step 3- Assembly Language Sample Program
Memory Hex
Label Mnemonics Comments
Address Code
ORG 0000h
C:0x0000 7805 UP1: MOV R0, #05H ;Initialize pass counter
;Initialize memory
C:0x0002 903000 MOV DPTR,#3000H
pointer
C:0x0005 7904 UP: MOV R1, #04H ;Initialize byte counter
;Save the lower byte
C:0x0007 AA82 MOV R2, DPL
address
C:0x0009 E0 MOVX A, @DPTR ;Read number from array
;Transfer the number to B
C:0x000A
F5F0 MOV 0F0H, A register
C:0x000C A3 INC DPTR ;Increment memory pointer
;Read next number from
C:0x000D E0 MOVX A, @DPTR
array
;Compare number with next
C:0x000E
B5F002 CJNE A, 0F0H, DN number
C:0x0011 011C AJMP SKIP
;If number>next number
C:0x0013 5007 DN: JNC SKIP
then go to SKIP
;Else exchange the
C:0x0015 8A82 MOV DPL, R2
number with next number
C:0x0017 F0 MOVX @DPTR, A
C:0x0018 A3 INC DPTR
C:0x0019 E5F0 MOV A, 0F0H
C:0x001B F0 MOVX @DPTR, A
;Decrement byte and if
C:0x001C D9E7 SKIP: DJNZ R1, UP count byte is not zero
go to Up
;Decrement pass counter
C:0x001E D8E0 DJNZ R0, UP1
and if not zero go to UP1
END
72
EXERCISES
Problem statement #1: Write ALP for arranging five numbers in descending order
stored in external memory location 2000H.
73
Step 3- Assembly Language Program
Memory
Hex Code Label Mnemonics Comments
Address
Observations for sample program (use blank sheet provided if space not sufficient)
3000H 3000H
3001H 3001H
3002H 3002H
3003H 3003H
3004H 3004H
3005H 3005H
Interpretation of Results for problem statement 1 (Give meaning of the above obtained results)
74
Practical Related Questions
1. Write a program to
(a) load the accumulator with the value 55H, and
(b) complement the ACC 7 times.
2. Discuss the program ROM space allocation for each of the following cases.
(a) EA’ = 0 for the 8751 (89C51) chip.
(b) EA’ = Vcc with both on-chip and off-chip ROM for the 8751.
(c) EA’ = Vcc with both on-chip and off-chip ROM for the 8752.
75