You are on page 1of 29

Assignment 2

1. Place the number 3Bh in internal RAM location 30h to 32h


Method 1
MNEMONIC COMMENT

MOV 30h,#3Bh ; Move the data 3Bh in location 30h


MOV 31h,#3Bh ; Move the data 3Bh in location 31h
MOV 32h,#3Bh ; Move the data 3Bh in location 32h

Method 2

MNEMONIC COMMENT

MOV A,#3Bh ; Move the data 3Bh in the accumulator


MOV 30h,A ; Transfer accumulator data 3Bh in
location 30h
MOV 31h,A ; Transfer accumulator data 3Bh in
location 31h
MOV 32h,A ; Transfer accumulator data 3Bh in
location 32h
2. Copy the data at internal RAM location 70h to R0 and R3. (Assume bank 0)

Method 1
MNEMONIC COMMENT

MOV 00h,70h ; Move contents of location 70h to


register R0 (00h)
MOV 03h,70h ; Move contents of location 70h to
register R3 (03h)

Method 2

MNEMONIC COMMENT

MOV D0h,#00h ; Select bank 0 by putting 00h in PSW


(D0h)
MOV R0,70h ; Move contents of location 70h to
register R0 (bank 0)
MOV R3,70h ; Move contents of location 70h to
register R3 (bank 0)
3. Set the SP at the byte address just above the last working register address

MNEMONIC COMMENT

MOV 81h,#1Fh ; SP (81h) is set to 1Fh, so that when it


starts storing it increments and starts
storing in the location just after the last
working register (1Fh  R7 of bank 3), which
is 20h.
4. Exchange the contents of the SP and the PSW
Method 1
MNEMONIC COMMENT

MOV A, 81h ; Save contents of SP in the accumulator


temporarily.
MOV 81h, D0h ; Move contents of PSW (D0h) into the SP
(81h)
MOV D0h, A ; Gets the original contents of the SP which
are stored in the accumulator to the PSW
(D0h).

Method 2
MNEMONIC COMMENT

MOV A, 81h ; Save contents of SP in the accumulator coz


exchange can be used only with accumulator and other
register or memory location.
XCH A,D0h ; exchange the contents of the accumulator (which is
having the contents of SP) with that of the PSW (D0h).
MOV 81h, A ; PSW contents that have come in the accumulator
after exchange, are transferred to the SP (81h).
5. Copy the byte at internal RAM address 27h to external RAM address 27h
Method 1
MNEMONIC COMMENT

MOV A, 27h ;Move the contents of internal RAM


location 27h into the accumulator.
MOV R0,#27h ;Load R0 with 27h, so that you can make
use of it for indirect addressing.
MOVX @R0,A ;Move the contents of the accumulator now
into the external location pointed by the
register R0 (27h)

Method 2
MNEMONIC COMMENT

MOV A, 27h ;Move the contents of internal RAM


location 27h into the accumulator.
MOV DPTR,#0027h ;Point the DPTR to the external RAM
location 27h.
MOVX @DPTR,A ;Move the contents of the accumulator now
into the external location pointed by the
DPTR (27h)
6. Set the Timer 1 to A23Dh
Method 1
MNEMONIC COMMENT

MOV 8B,#3Dh ;TL1 (8Bh) is loaded with the lower byte


3Dh.
MOV 8D, #A2h ;TH1 (8Dh) is loaded with the higher byte
A2h.
7. Copy the contents of DPTR to register R0 (DPL) and R1 (DPH)
Method 1
MNEMONIC COMMENT

MOV 00h, 82h ;Move the contents of DPL (82h) into R0


(00h) register.
MOV 01h, 83h ;Move the contents of DPH (83h) into R1
(01h) register.

Method 2

MNEMONIC COMMENT

MOV D0h, 00h ; Select bank 0 by putting 00h in PSW


(D0h)
MOV R0h, 82h ;Move the contents of DPL (82h) into R0
(00h) register of bank 0.
MOV R1h, 83h ;Move the contents of DPH (83h) into R1
(01h) register of bank 0.
8. Copy the data in external RAM location 0123h to TL0 and the data in
external RAM location 0234h to TH0
Method 1
MNEMONIC COMMENT

MOV DPTR, #0123h ; Load address 0123h in the data pointer.


MOVX A,@DPTR ; Move contents of the external memory
location (0123h) pointer by the DPTR, into
the accumulator
MOV 8Ah,A ; Move contents of the accumulator into
TL0 (8Ah)
MOV DPTR, #0234h ; Load address 0234h in the data pointer.
MOVX A,@DPTR ; Move contents of the external memory
location (0234h) pointer by the DPTR, into
the accumulator
MOV 8Ch,A ; Move contents of the accumulator into
TH0 (8Ch)
9. Copy the data in internal RAM location 12h to 15h to internal RAM
location 20h to 23h; Copy 12h to 20h, 13h to 21h, etc.
Method 1
MNEMONIC COMMENT

MOV 20h, 12h ; Move the contents of location 12h to


location 20h.
MOV 21h, 13h ; Move the contents of location 13h to
location 21h.
MOV 22h, 14h ; Move the contents of location 14h to
location 22h.
MOV 23h, 15h ; Move the contents of location 15h to
location 23h.
10. Set the SP register to 07h and PUSH the SP register on the stack; predict
what number is PUSHed to address 08h.
Method 1
MNEMONIC COMMENT

MOV 81h, #07h ; Stack pointer points to 07h


PUSH 81h ; PUSH SP register on the stack
Ans: Stack pointer which is pointing at 07
will increment and store data in 08h stack
location the contents of 81h (SP) which is
08h.
11. Exchange the contents of the B register and external RAM address 02CFh.

Method 1
MNEMONIC COMMENT

MOV DPTR,#02CFh ; Load address 02CFh in the data pointer.


MOVX A,@DPTR ; Move contents of the external memory
location pointed by the DPTR into the
accumulator
XCH A,0F0h ; Exchange contents of the accumulator
with register B (0F0h)
MOVX @DPTR,A ; contents of register B which were
transferred to the accumulator are moved
in external memory pointer by the DPTR.
12. Rotate the byte in registers R0 to R3; Copy the data in R0 to R1, R1 to R2,
R2 to R3 and R3 to R0.
Method 1
MNEMONIC COMMENT

MOV A,03h ; Save the contents of R3 to accumulator


MOV 03h,02h ; Move contents of R2 to R3
MOV 02h,01h ; Move contents of R1 to R2
MOV 01h,00h ; Move contents of R0 to R1
MOV 00h,A ; Move contents of Accumulator to R0
13. Copy the external code byte at address 007Dh to the SP.

Method 1
MNEMONIC COMMENT

MOV DPTR,#007Ch ; Load address 007Ch in the data pointer.


MOV A,#01h ; Load accumulator with 01h
MOVC A,@A+DPTR ; [A+DPTR = 01+007C = 007D]; Code byte
from external memory 007Dh are moved to the
accumulator
MOV 81h,A ; Contents of the accumulator moved to SP
(81h).
14. Copy the data in register R5 to external RAM address 032Fh.

Method 1
MNEMONIC COMMENT

MOV DPTR,#032Fh ; Load address 032Fh in the data pointer.


MOV A,05h ; Move contents of R5 to the accumulator
MOVX @DPTR,A ; Move the contents of the accumulator
into the external memory pointed by the
DPTR.
15. Copy the internal code byte at address 0300h to external RAM address
0300h
Method 1
MNEMONIC COMMENT

MOV DPTR,#0300h ; Load address 0300h in the data pointer.


MOV A,@DPTR ; Move the contents of memory location
pointed by DPTR (0300h) into the
accumulator
MOVX @DPTR,A ; Move the contents of accumulator to
external memory location pointed by DPTR
(0300h).
16. Swap the bytes in timer 0: put TL0 in TH0 and TH0 in TL0
Method 1
MNEMONIC COMMENT

MOV A,8Ah ; Save the contents of TL0 (8Ah) in


accumulator.
MOV 8Ah,8Ch ; Move the contents of TH0 (8Ch) into TL0
(8Ah).
MOV 8Ch,A ; Move the contents of TL0 which were
earlier saved in accumulator into TH0.

Method 2
MNEMONIC COMMENT

MOV A,8Ah ; Save the contents of TL0 (8Ah) in


accumulator.
XCH A,8Ch ; Swap the contents of TH0 (8Ch) and the
accumulator which was holding the contents
of TL0.
MOV 8Ah,A ; Move contents of the accumulator
(contents of TH0) into TL0 (8Ah)
17. Store DPTR in external RAM location 0123h (DPL) and 02BCh (DPH)
Method 1
MNEMONIC COMMENT

MOV 00h, 82h ; Store the original contents of DPL in


R0.
MOV 01h, 83h ; Store the original contents of DPH in R1.
MOV DPTR,#0123h ; Load address 0123h in the data pointer.
MOV A,00h ; Move contents of DPL (82h), stored in
R0, into accumulator
MOVX @DPTR,A ; Load contents of accumulator which had
contents of 82h(DPL) into external RAM
address 0123h.
MOV DPTR,#02BCh ; Load address 02BCh in the data pointer.
MOV A,01h ; Move contents of DPH (83h), stored in
R1, into accumulator
MOVX @DPTR,A ; Load contents of accumulator which had
contents of 83h(DPH) into external RAM
address 02BCh.
18. Exchange both low nibbles of registers R0 and R1; put the lower nibble of
R0 in R1 and the low nibble of R1 to R0.

Method 1

MNEMONIC COMMENT

MOV A,01h ; Accumulator is holding contents of R1


(01h)
MOV R3;#00h ; R3 is holding address of R0 (00h)
XCHD A,@R3 ; Lower nibble of what is addressed by R3
(contents of R0) are exchanged with the
lower nibble of accumulator (which had R1
data) R1R0
MOV 01h,A ; Contents of accumulator moved to R1
(R0R1)
19. Store the contents of register R3 at the internal RAM address contained in
R2

Method 1

MNEMONIC COMMENT

MOV D0h, 00h ; Select bank 0 by putting 00h in PSW


(D0h)
MOV @R2,03h Move contents of R3 in the locations
contained in R2.
[since MOV @Rr, Rr not allowed  Don’t use
MOV @R2,R3]
20. Store the contents of RAM location 20h at the address contained in RAM
location 08h

Method 1

MNEMONIC COMMENT

MOV D0h, 08h ; Select bank 1 by putting 08h in PSW


(D0h)
MOV @R0,20h Move the contents of location 20h into the
RAM location pointed by 08h(R0 of bank 1)
21. Store Register A at the internal RAM location address in register A

Method 1

MNEMONIC COMMENT

MOV R0,A ; Move contents of accumulator is register


R0.
MOV @R0,A ; Move contents of accumulator in the RAM
location addressed by R0
22. Copy program bytes 0100h to 0102h to internal RAM location 20 to 22h

Method 1

Since
LABEL MNEMONIC COMMENT
MOV DPTR,#0100H ; Initializing DPTR to source
address 0100H
MOV R0,#03H ; Count=3
MOV R1,#20H ;Initializing R1 to destination
address 20H
STORE: MOV A,00H
MOVC A,@A+DPTR ; Contents of source address
moved to A
MOV @R1,A ; Contents of A moved to
destination address
INC DPTR ; Increment source address
INC R1 ; Increment destination address
DJNZ R0,STORE ; Continue for three successive
locations
23. Copy the data on the pins of Port 2 to the Port 2 latch

Method 1

MNEMONIC COMMENT

MOV A,0A0H ; Read the Port2 pins


MOV 0A0H,A ; Output data on the Port2 latch from
Accumulator
24. Push the contents of the B register to TMOD

Method 1

MNEMONIC COMMENT

MOV 81H,#88H ; Initialize SP to 88H since TMOD=89H


PUSH 0F0H ; Push from Register B to where the SP is
pointing. [SP=SP+1=89H]

Method 2

MNEMONIC COMMENT

PUSH 0F0H ; Push from register B (0F0H)


POP 89H ; Pop into TMOD (89H)
25. Copy the contents of external code memory address 0040H to IE

Method 1

MNEMONIC COMMENT

MOV DPTR,#0040 ; Initialize DPTR to 0040H


MOV A,#00H ; Clear Accumulator
MOVC A,@A+DPTR ; Move contents of external code (0040H)
memory into A
MOV 0A8H,A ; Move contents of A into IE register
26. Show that set of XCH instructions executes faster than a PUSH and POP
when saving the contents of A register

Method 1

MNEMONIC COMMENT

XCH A, 0F0H ; Exchange contents of A and B [2bytes]

Method 2
MNEMONIC COMMENT

PUSH 0E0H ; Push A on stack


PUSH 0F0H ; Push B on Stack
POP 0E0H ; Pop B into register A
POP 0F0H ; Pop A into register B
[8bytes]
27. Use the debugger to determine if pin data or latch data is POPed from a
port.

Method 1

MNEMONIC COMMENT
28. Swap the contents of register bank 3 with register bank 0 as follows: R0 of bank3
with R0 of bank 0, R1 of bank3 with R1 of bank 0, and so on, until R7 of bank3 is
swapped with R7 of bank 0.
Method 1

LABEL MNEMONIC COMMENT

MOV D0,#08H ; select bank 1


MOV R0,#00H ; R0 of bank 1 is pointing to R0 of bank
0.
MOV R1,#18H ; R1 of bank 1 is pointing to R0 of bank
3.
MOV R2,#08H ; counter
UP: MOV A,@R0 ; Contents of location pointed by R0.
i.e bank 0 registers move into A
XCH A,@R1 ;Exchange the contents of A with the
contents of the bank 3 registers
MOV @R0,A
INC R0 ;Increment Pointer R0 pointing to bank 0
INC R1 ;Increment Pointer R1 pointing to bank 3

DJNZ R2, UP ;Repeat to exchange the next set of


registers

You might also like