Lecture Topic 1.3.4
Lecture Topic 1.3.4
2. Write a program to store data FFH into RAM memory locations 50H to 58H using direct
addressing mode.
ORG 0000H ; Set program counter 0000H
MOV A, #0FFH ; Load FFH into A
MOV 50H, A ; Store contents of A in location 50H
MOV 51H, A ; Store contents of A in location 5IH
MOV 52H, A ; Store contents of A in location 52H
MOV 53H, A ; Store contents of A in location 53H
MOV 54H, A ; Store contents of A in location 54H
MOV 55H, A ; Store contents of A in location 55H
MOV 56H, A ; Store contents of A in location 56H
MOV 57H, A ; Store contents of A in location 57H
MOV 58H, A ; Store contents of A in location 58H
END
3. Write a program to subtract a 16 bit number stored at locations 51H-52H from 55H-56H and
store the result in locations 40H and 41H. Assume that the least significant byte of data or the
result is stored in low address. If the result is positive, then store 00H, else store 01H in 42H.
OPT 0000H
MOV R0, #50H
MOV R3, #0AH
Loopl: INC @R0
INC R0
DJNZ R3, loopl END
END
11.Write a program to find the average of five 8 bit numbers. Store the result in H. (Assume that after
adding five 8 bit numbers, the result is 8 bit only).
ALGORITHM
● Step 1: Initialize external data memory with data and DPTR with address
● Step 2: Load A and TEMP with the operands
● Step 3: Are the two operands equal? If yes, go to step 9
● Step 4: Is (A) greater than (TEMP)? If yes, go to step 6
● Step 5: Exchange (A) with (TEMP) such that A contains the bigger number
● Step 6: Perform division operation (contents of A with contents of TEMP)
● Step 7: If the remainder is zero, go to step 9
● Step 8: Move the remainder into A and go to step 4
● Step 9: Save the contents of TEMP in memory and terminate the program
ORG 0000H ; Set program counter 0000H
TEMP EQU 70H
TEMPI EQU 71H
MOV DPTR, #1000H ; Copy address 1000H to DPTR
MOVX A, @DPTR ; Copy First number to A
MOV TEMP, A ; Copy First number to temp
INC DPTR
MOVX A, @DPTR ; Copy Second number to A
LOOPS: CJNE A, TEMP, LOOP1 ; (A) /= (TEMP) branch to LOOP1
AJMP LOOP2 ; (A) = (TEMP) branch to LOOP2
LOOP1: JNC LOOP3 ; (A) > (TEMP) branch to LOOP3
MOV TEMPI, A ; (A) < (TEMP) exchange (A) with (TEMP)
MOV A, TEMP
MOV TEMP, TEMPI
LOOP3: MOV B, TEMP
DIV AB ; Divide (A) by (TEMP)
MOV A, B ; Move remainder to A
CJNE A, #00, LOOPS ; (A)/=00 branch to LOOPS
LOOP2: MOV A, TEMP
MOV DPTR, #2000H
MOVX @DPTR, A ; Store the result in 2000H
END
A.TEXTBOOKS/REFERENCE BOOKS
i. TEXTBOOKS
T1 Kenneth Ayala, The 8051 Microcontroller, Cengage Learning India, 3rd Edition, Nov 2007
T2 B. Kanta Rao, Embedded Systems, PHI, 1st Edition, January 2011
T3 John Boxall, Arduino Workshop: A Hands-On Introduction with 65 Projects, No Starch Press, 1st
Edition, May 2013
B. Video Links:
1.https://www.youtube.com/watch?v=g7Gypl9zNz8
2.https://www.youtube.com/watch?v=nIZdkdjuLMc
3.https://www.youtube.com/watch?v=Vrazx7AsutM
4.https://www.youtube.com/watch?v=dsBR1rP2kmY