MC 2
MC 2
Module – 2 Notes
Prepared By: Malashree G ,HOD, Department of E&C,Dr.SMCE
E-1: Introduction to 8051 assembly programming: [Additional topic for extended learning]
Machine language:
The CPU can understand and work only on binary digits and it can do so at a very high speed. In the early
days of the computer, programmers coded programs in machine language which consists of 0s & 1s.
Although the hexadecimal system was used as a more efficient way to represent binary numbers, the process
of working in machine code was still cumbersome for humans.
Assembly language (Low-level language):
Complexity in machine language programming, eventually, led to the development of Assembly Language
that provided mnemonics for the machine code instructions, plus other features that made programming
faster and less prone to error. The term mnemonic refer to codes and abbreviations that are relatively easy to
remember. Assembly language programs must be translated into machine code by a program called an
assembler. Assembly language is referred to as a low-level language because it deals directly with the
internal structure of the CPU. To program in Assembly language, the programmer must know all the
registers of the CPU and the size of each, as well as other details.
High-Level language:
The languages such as BASIC, Pascal, C, C++, Java, and numerous others are called high-level languages
because the programmer does not have to be concerned with the internal details of the CPU: Whereas an
assembler is used to translate an Assembly language program into machine code (sometimes also called
object code or opcode for operation code), high-level languages are translated into machine code by a
program called a compiler.
Structure of Assembly language:
An Assembly language program consists of, among other things, a series of lines of Assembly language
instructions.
An Assembly language instruction consists of four fields:
[label:] mnemonic [operands] [; comment]
Brackets indicate that a field is optional, and not all lines have them. Brackets should not be typed in.
Regarding the above format, the following points should be noted. .
Page 1 of 22
1. The label field allows the program to refer to a line of code by name. The label field cannot exceed a
certain number of characters. Check the assembler for the rule.
2. The Assembly language mnemonic (instruction) and operand(s) fields together perform the real work of
the program and accomplish the tasks for which the program was written.
3. The comment field begins with a semicolon comment indicator ";". Comments may be at the end of a line
or on a line by themselves. The assembler ignores comments, but they are indispensable to programmers.
Although comments are optional, it is recommended that they be used to describe the program and make it
easier for someone else to read and understand, or for the programmer to remember what they wrote.
4. Any label referring to an instruction must be followed by a colon symbol, ":".
Sample of an Assembly Language Program
ORG 0H ; start (origin) at location 0
MOV R5, #25H ; load 25H into R5
MOV R7, #34H ; load 34H into R7
MOV A, #0 ; load 0 into A
ADD A, R5 ; add contents of R5 to A, now A = A + R5
ADD A, R7 ; add contents of R7 to A, now A = A + R7
ADD A, # 12H ; add to A value 12H, now A = A + 12H
Here: SJMP HERE ; stay in this loop
END ; end of asm source file
A given Assembly language program is a series of statements, or lines; which are either assembly language
instructions such as ADD and MOV, or statements called directives.
While instructions tell the CPU what to do, directives (also called pseudo-instructions) give directions to the
assembler. For example, in the above program while the MOV and ADD instructions are commands to the
CPU, ORG and END are directives to the assembler. ORG tells the assembler to place the opcode at memory
location 0 while END indicates to the assembler the end of the source code. In other words, one is for the
start of the program and the other one for the end of the program.
Assembling and Running an 8051 program:
The steps to create an executable Assembly language program are outlined as follows as shown in fig. 1:
1. An Editor program is used to type a assembly program. Many excellent editors or word processors are
available that can be used to create and/or edit the program. A widely used editor is the MS-DOS EDIT
program (or Notepad in Windows), which comes with all Microsoft operating systems. The editor must be
able to produce an ASCII file. For many assemblers, the file names follow the usual DOS conventions,
but the source file has the extension "asm" or "src", depending on the assembler.
2. The" asm" source file containing the program code created in step 1 is fed to an 8051 assembler. The
assembler converts the instructions into machine code. The assembler will produce an object file and a list
file. The extension for the object file is "obj" while the extension for the list file is "lst".
3. Assemblers require a third step called linking. The link program takes one or more object files and
produces an absolute object file with the extension "abs". This abs file is used by 8051 trainers that have a
monitor program. The list file is as shown below.
Page 2 of 22
4. 0004 74 00 MOV A, #0 ; load 0 into A
; add contents of R5 to A ; now A = A +
5. 0006 2D ADD A, R5
R5
; add contents of R57to A; now A = A +
6. 0007 2F ADD A, R7
R7
7. 0008 24 12 ADD A, #12H ; add to A value 12H ; now A = A+12H
8. 000A 80 0A HERE: SJMP HERE ; stay in this loop
9. 000C END ; end of asm source file
List file: The list file, which is optional, is very useful to the programmer because it lists all the opcodes
and addresses as well as errors that the assembler detected. Many assemblers assume that the list file is
not wanted unless you indicate that you want to produce it. This file can be accessed by an editor such as
DOS EDIT and displayed on the monitor or to the printer to produce a hard copy. The programmer uses
the list file to find syntax errors. It is only after fixing all the errors indicated in the list file that the obj file
is ready to be input to the linker program.
4. The "abs" file is fed into a program called "OH" (object to hex converter), which creates a file with
extension "hex" that is ready to burn into ROM. 'This program comes with all 8051 assemblers. Recent
Windows-based assemblers combine steps 2 through 4 into one step.
Page 3 of 22
the "D" after the decimal number is optional but using "B" (binary) and "H" (hexadecimal) for the others is
required. Regardless of which is used, the assembler will convert the numbers into hex. To indicate ASCII,
simply place the characters in quotation marks ('like this'). The assembler will assign the ASCII code for the
numbers or characters automatically. The DB directive is the only directive that can be used to define ASCII
strings larger than two characters; therefore, it should be used for all ASCII data definitions. DB is also used
to allocate memory in byte-sized chunks.
Following are some DB examples:
Either single or double quotes can be used around ASCII strings.
ORG 500H
DATA1: DB 28 ; DECIMAL (1C in hex)
DATA2: DB 00110101B ; BINARY (35 in hex)
DATA3: DB 39H ; HEX
ORG 510H
DATA4: DB “2591” ; ASCII NUMBERS
ORG 518H
DATA6: DB “I Love my culture” ; ASCII CHARACTERS
Assembler directives:
The following are some more widely used directives of the 8051.
ORG (origin):
The ORG directive is used to indicate the beginning of the address. The number that comes after ORG can be
either in hex or in decimal. If the number is not followed by H, it is decimal, and the assembler will convert it
to hex. Based on the assembler “. ORG” or “ORG” notation is used.
Ex: ORG 500h
EQU (equate):
This is used to define a constant without occupying a memory location. The EQU directive does not set aside
storage for a data item but associates a constant value with a data label so that when the label appears in the
program, its constant value will be substituted for the label. The following uses EQU for the counter constant
and then the constant is used to load the R3 register.
Ex: COUNT EQU 25
... ....
MOV R3, #COUNT
Advantage of using EQU?
Assume that there is a constant (a fixed value) used in many different places in the program, and the
programmer wants to change its value throughout. By the use of EQU, the programmer can change it once
and the assembler will change all of its occurrences, rather than search the entire program trying to find every
occurrence.
END:
This indicates to the assembler the end of the source (asm) file. The END directive is the last line of an 8051
program, meaning that in the source code anything after the END directive is ignored by the assembler.
Some assemblers use “. END” instead of “END”.
Page 4 of 22
Rules for labels in Assembly language:
• Each label name must be unique.
• The names used for labels in Assembly language programming consist of alphabetic letters in both
uppercase and lowercase, the digits 0 through 9, and the special characters question mark (?), period (.), at
(@), underline (_), and dollar sign ($).
• The first character of the label must be an alphabetic character, it cannot be a number.
• Every assembler has some reserved words that must not be used as labels in the program. Foremost
among the reserved words are the mnemonics for the instructions.
Page 5 of 22
2.1 8051 Addressing modes:
The method of specifying the operands in the instructions is called addressing mode.
Or
The method of supplying the data for the instruction’s operation is called addressing mode.
Page 6 of 22
02 0800 – 0FFFh 0000 1000 0000 0000 to
0000 1111 1111 1111
03 1000 – 17FFh 0001 0000 0000 0000 to
0001 0111 1111 1111
04 1800 – 1FFFh 0001 1000 0000 0000 to
0001 1111 1111 1111
05 2000 – 2FFFh 0010 0000 0000 0000 to
0010 0111 1111 1111
-- -- --
-- -- --
Page 7 of 22
2.2 Instruction set of 8051:
2.2.1 Data Transfer Instructions:
Data transfer instructions move (copy) one source operand to another destination operand. Source and
destination operands may be as shown in the below table:
The various data transfer instructions available in 8051 are tabulated below:
Sl. Sl.
Instruction Operation Instruction Operation
No. No.
1. MOV A, Rn A Rn 16. MOV DPTR, #imm16 DPTR imm16
A Rn
2. MOV A, data_addr A [data_addr] 17. XCH A, Rn
Rn A
A [data_addr]
3. MOV A, @Ri A [Ri] 18. XCH A, data_addr
[data_addr] A
A [Ri]
4. MOV A, #imm8 A imm8 19. XCH A, @Ri
[Ri] A
5. MOV Rn, A Rn A 20. MOVX A, @Ri A [Ri]
6. MOV Rn, data_addr Rn [data_addr] 21. MOVX @Ri, A [Ri] A
7. MOV Rn, #imm8 Rn imm8 22. MOVX A, @DPTR A [DPTR]
8. MOV data_addr, A [data_addr] A 23. MOVX @DPTR, A [DPTR] A
9. MOV data_addr, Rn [data_addr] Rn 24. MOVC A, @A+PC A [A+PC]
[data_addr] MOVC A,
10. MOV data_addr, @Ri 25. A [A+DPTR]
@Ri @A+DPTR
Page 8 of 22
MOV data_addr, [data_addr] SP SP+1
11. 26. PUSH data_addr
#imm8 imm8 [SP] [data_addr]
MOV data_addr, [data_addr] [data_addr] [SP]
12. 27. POP data_addr
data_addr [data_addr] SP SP-1
13. MOV @Ri, A [Ri] A 28. MOV port, A Port A
14. MOV @Ri, #data [Ri] imm8 29. MOV A, Port A Port
15. MOV @Ri, data_addr [Ri] [data_addr]
Fig. shows that registers R0, R1, and DPTR can be used to hold the address of the data byte in external
RAM. R0 & R1 are limited to external RAM address ranges of 00h to 0FFh, while the DPTR register can
address the maximum RAM space of 0000h to 0FFFFh.
Page 9 of 22
Code Memory Read-Only Data Moves:
There are times when the data must be permanent to be of repeated use and is stored in the program ROM
using assembler directives that store the programmed data anywhere in ROM that the programmer wishes.
Access to this data is made possible by using indirect addressing and the A register in conjunction with either
the PC or the DPTR as shown in fig. in both the cases, the number in register A is added to the pointing
register to form the address in ROM where the desired data is to be found. The data is then fetched from the
ROM address so formed and placed in the A register. The original data in A is lost, and the addressed data
takes its place.
Note:
i) The PC is incremented by 1 (to point to the next instruction) before it is added to A to form the final
address of the code byte.
ii) All data is moved from the code memory to the A register.
iii) MOVC is normally used with internal or external ROM and can address 4K of internal or 64K of
external code.
A PUSH opcode copies data from the source address to the stack. SP is incremented by 1 before the data is
copied to the internal RAM location contained in SP so that the data is stored from low addresses to high
addresses in the internal RAM. The stack grows up in memory as it is PUSHed. Excessive PUSHing can
make the stack exceed 7Fh (the top of internal RAM), after which the PUSHed data is lost.
A POP opcode copies data from the stack to the destination address. SP is decremented by 1 after data is
copied from the stack RAM address to the direct destination to ensure that data placed on the stack is
retrieved in the same order as it was stored.
The SP register is set to 07h when the 8051 is reset, which is the same direct address in internal RAM as
register R7 in bank 0. The first PUSH opcode would write data to R0 of bank 1. The SP should be initialized
Page 10 of 22
by the programmer to point to an internal RAM address above the highest address likely to be used by the
program.
NOTE:
i) When the SP reaches FFh it “rolls over” to 00h (R0).
ii) RAM ends at address 7Fh; PUSHes above 7Fh result in errors.
iii) The SP is usually set at addresses above the register banks.
iv) The SP may be PUSHed & POPed to the stack.
v) Note that direct addresses, not register names, must be used for R0-R7. The stack mnemonics have no
way of knowing which bank is in use.
Sl.
Instruction Operation Source operands
No.
1. ANL A, Src A A &Src Imm8, Rn, data_addr, @Ri
Page 11 of 22
3. ANL data_addr, #imm8 [data_addr] [data_addr] &imm8 No other operands used
4. ORL A, Src A A ¦Src Imm8, Rn, data_addr, @Ri
5. ORL data_addr, A [data_addr] [data_addr] ¦ A No other operands used
6. ORL data_addr, #imm8 [data_addr] [data_addr] ¦ imm8 No other operands used
7. XRL A, Src A A^ Src Imm8, Rn, data_addr, @Ri
8. XRL data_addr, A [data_addr] [data_addr] ^ A No other operands used
9. XRL data_addr, #imm8 [data_addr] [data_addr] ^imm8 No other operands used
Page 12 of 22
iv) SP SP – 1
Short jump instruction is to a relative address within -128 and + 127. Absolute jump instruction is to
direct 11-bit address in program memory. Long jump instruction is to direct 16-bit address in program
memory. Jump instruction is pointed by A + @DPTR.
Program flow control in a subroutine call is by absolute call or long call instruction. Absolute call
instruction is to call a specified direct 11-bit address at program memory. Long call instruction is to call a
specified direct 16-bit address directly at program memory. Return from a called routine is by RET
instruction and return from interrupt service routine is by RETI.
In conditional branching instructions, the content of the PC is modified, only if the condition specified in
the instruction is true.
➢ Only relative addressing mode (Short Jumps) is used.
➢ The conditional branching instructions are normally used immediately after the arithmetic/logical
operations so that branching can occur based on a condition specified.
The various forms of conditional branching instructions and its operations are tabulated in the below table:
Sl.
Instruction Operation Remarks
No.
i) PC PC + 2
ii) If (A = 0)
1. JZ code_offset Jump if result in A is zero
PCPC + code_offset
Else, Next instruction is executed
i) PC PC + 2
ii) If (A ≠ 0)
2. JNZ code_offset Jump if result in A is not zero
PCPC + code_offset
Else, Next instruction is executed
i) PC PC + 2
ii) If (CF = 0)
3. JC code_offset Jump if carry flag
PCPC + code_offset
Else, Next instruction is executed
i) PC PC + 2
ii) If (CF ≠ 0)
4. JNC code_offset Jump if no carry flag
PCPC + code_offset
Else, Next instruction is executed
i) PC PC + 3
ii) If ([bit_addr] = 1)
5. JB bit_addr, code_offset Jump if bit set
PCPC + code_offset
Else, Next instruction is executed
i) PC PC + 3
JNB bit_addr, ii) If ([bit_addr] ≠1) {i.e.
6. Jump if no bit
code_offset [bit_addr]=0}
PCPC + code_offset
Page 13 of 22
Else, Next instruction is executed
Next instruction will be executed
i) PC PC + 3
ii) If ([bit_addr] =1)
JBC bit_addr,
7. PCPC + code_offset Jump if bit set & clear it
code_offset
[bit_addr]=0
Else, Next instruction is executed
Compare & jump if not equal
to
i) PC PC + 3
Other forms:
ii) If ( A ≠ [data_addr])
ii) CJNE A, #imm8,
CJNE A, data_addr, PCPC + code_offset
8. code_offset
code_offset Also, if A< [data_addr], CF = 1
iii) CJNE Rn, #imm8,
A > [data_addr], CF = 0
code_offset
Else, Next instruction is executed
iv) CJNE @Ri, #imm8,
code_offset
i) PC PC + 2
ii) Rn Rn – 1 Decrement & jump if not zero
9. DJNZ Rn, offset iii) If (Rn ≠ 0) ii) DJNZ data_addr,
PCPC + code_offset code_offset
Else, Next instruction is executed
Page 14 of 22
3. RL A No flags
4. RR A No flags
5. RLC A CF
6. RRC A CF
7. SWAP A No flags
Page 15 of 22
Annexure: HEX codes of the instructions of 8051 microcontroller
No. of
Sl. No. of
Mnemonic Operands Hex Code Machine
No. Bytes
cycles
1. NOP 00 1 1
2. AJMP Addr11 01 2 2
3. LJMP Addr16 02 3 2
4. RR A 03 1 1
5. INC A 04 1 1
6. INC Data_ addr 05 2 1
7. INC @R0 06 1 1
8. INC @R1 07 1 1
9. INC R0 08 1 1
10. INC R1 09 1 1
11. INC R2 0A 1 1
12. INC R3 0B 1 1
13. INC R4 0C 1 1
14. INC R5 0D 1 1
15. INC R6 0E 1 1
16. INC R7 0F 1 1
17. JBC Bit_addr, code_addr 10 3 2
18. ACALL Code_addr 11 2 2
19. LCALL Code_addr 12 3 2
20. RRC A 13 1 1
21. DEC A 14 1 1
22. DEC Data_ addr 15 2 1
23. DEC @R0 16 1 1
24. DEC @R1 17 1 1
25. DEC R0 18 1 1
26. DEC R1 19 1 1
27. DEC R2 1A 1 1
28. DEC R3 1B 1 1
29. DEC R4 1C 1 1
30. DEC R5 1D 1 1
31. DEC R6 1E 1 1
32. DEC R7 1F 1 1
33. JB Bit_addr, Code_addr 20 3 2
34. AJMP Code_addr 21 2 2
35. RET 22 1 2
36. RL A 23 1 1
37. ADD A, #data 24 2 1
38. ADD A, data_addr 25 2 1
39. ADD A, @R0 26 1 1
40. ADD A, @R1 27 1 1
41. ADD A, R0 28 1 1
42. ADD A, R1 29 1 1
43. ADD A, R2 2A 1 1
44. ADD A, R3 2B 1 1
45. ADD A, R4 2C 1 1
Page 16 of 22
46. ADD A, R5 2D 1 1
47. ADD A, R6 2E 1 1
48. ADD A, R7 2F 1 1
49. JNB Bit_addr, code_addr 30 3 2
50. ACALL Code_addr 31 2 2
51. RETI 32 1 2
52. RLC A 33 1 1
53. ADDC A, #data 34 2 1
54. ADDC A, data_addr 35 2 1
55. ADDC A, @R0 36 1 1
56. ADDC A, @R1 37 1 1
57. ADDC A, R0 38 1 1
58. ADDC A, R1 39 1 1
59. ADDC A, R2 3A 1 1
60. ADDC A, R3 3B 1 1
61. ADDC A, R4 3C 1 1
62. ADDC A, R5 3D 1 1
63. ADDC A, R6 3E 1 1
64. ADDC A, R7 3F 1 1
65. JC Code_addr 40 2 2
66. AJMP Code_addr 41 2 2
67. ORL Data_addr, A 42 2 1
68. ORL Data_addr, #data 43 3 2
69. ORL A, #data 44 2 1
70. ORL A, data_addr 45 2 1
71. ORL A, @R0 46 1 1
72. ORL A, @R1 47 1 1
73. ORL A, R0 48 1 1
74. ORL A, R1 49 1 1
75. ORL A, R2 4A 1 1
76. ORL A, R3 4B 1 1
77. ORL A, R4 4C 1 1
78. ORL A, R5 4D 1 1
79. ORL A, R6 4E 1 1
80. ORL A, R7 4F 1 1
81. JNC Code_addr 50 2 2
82. ACALL Code_addr 51 2 2
83. ANL Data_addr, A 52 2 1
84. ANL Data_addr, #data 53 3 2
85. ANL A, #data 54 2 1
86. ANL A, data_addr 55 2 1
87. ANL A, @R0 56 1 1
88. ANL A, @R1 57 1 1
89. ANL A, R0 58 1 1
90. ANL A, R1 59 1 1
91. ANL A, R2 5A 1 1
92. ANL A, R3 5B 1 1
93. ANL A, R4 5C 1 1
94. ANL A, R5 5D 1 1
Page 17 of 22
95. ANL A, R6 5E 1 1
96. ANL A, R7 5F 1 1
97. JZ Code_addr 60 2 2
98. AJMP Code_addr 61 2 2
99. XRL Data_addr, A 62 2 1
100. XRL Data_addr, #data 63 3 2
101. XRL A, #data 64 2 1
102. XRL A, data_addr 65 2 1
103. XRL A, @R0 66 1 1
104. XRL A, @R1 67 1 1
105. XRL A, R0 68 1 1
106. XRL A, R1 69 1 1
107. XRL A, R2 6A 1 1
108. XRL A, R3 6B 1 1
109. XRL A, R4 6C 1 1
110. XRL A, R5 6D 1 1
111. XRL A, R6 6E 1 1
112. XRL A, R7 6F 1 1
113. JNZ Code_addr 70 2 2
114. ACALL Code_addr 71 2 2
115. ORL C, bit_addr 72 2 2
116. JMP @A+DPTR 73 1 2
117. MOV A, #data 74 2 1
118. MOV Data_addr, #data 75 3 2
119. MOV @R0, #data 76 2 1
120. MOV @R1, #data 77 2 1
121. MOV R0, #data 78 2 1
122. MOV R1, #data 79 2 1
123. MOV R2, #data 7A 2 1
124. MOV R3, #data 7B 2 1
125. MOV R4, #data 7C 2 1
126. MOV R5, #data 7D 2 1
127. MOV R6, #data 7E 2 1
128. MOV R7, #data 7F 2 1
129. SJMP Code_addr 80 2 2
130. AJMP Code_addr 81 2 2
131. ANL C, bit_addr 82 2 2
132. MOVC A, @A+PC 83 1 2
133. DIV AB 84 1 4
134. MOV Data_addr, data_addr 85 3 2
135. MOV Data_addr, @R0 86 2 2
136. MOV Data_addr, @R1 87 2 2
137. MOV Data_addr, R0 88 2 2
138. MOV Data_addr, R1 89 2 2
139. MOV Data_addr, R2 8A 2 2
140. MOV Data_addr, R3 8B 2 2
141. MOV data addr, R4 8C 2 2
142. MOV Data_addr, R5 8D 2 2
143. MOV Data_addr, R6 8E 2 2
Page 18 of 22
144. MOV Data_addr, R7 8F 2 2
145. MOV DPTR, #data 90 3 2
146. ACALL Code_ addr 91 2 2
147. MOV Bit_addr, C 92 2 2
148. MOVC A, @A+DPTR 93 1 2
149. SUBB A, #data 94 2 1
150. SUBB A, data_addr 95 2 1
151. SUBB A, @R0 96 1 1
152. SUBB A, @R1 97 1 1
153. SUBB A, R0 98 1 1
154. SUBB A, R1 99 1 1
155. SUBB A, R2 9A 1 1
156. SUBB A, R3 9B 1 1
157. SUBB A, R4 9C 1 1
158. SUBB A, R5 9D 1 1
159. SUBB A, R6 9E 1 1
160. SUBB A, R7 9F 1 1
161. ORL C, /bit_addr A0 2 2
162. AJMP Code_addr A1 2 2
163. MOV C, bit_addr A2 2 1
164. INC DPTR A3 1 2
165. MUL AB A4 1 4
166. reserved A5
167. MOV @R0, data_addr A6 2 2
168. MOV @R1, data_addr A7 2 2
169. MOV R0, data_addr A8 2 2
170. MOV R1, Data_addr A9 2 2
171. MOV R2, Data_addr AA 2 2
172. MOV R3, Data_addr AB 2 2
173. MOV R4, Data_addr AC 2 2
174. MOV R5, Data_addr AD 2 2
175. MOV R6, Data_addr AE 2 2
176. MOV R7, Data_addr AF 2 2
177. ANL C, /bit_addr B0 2 2
178. ACALL Code_addr B1 2 2
179. CPL Bit_addr B2 2 1
180. CPL C B3 1 1
181. CJNE A, #data, code addr B4 3 2
182. CJNE A, data_addr, code_addr B5 3 2
183. CJNE @R0, #data, code_addr B6 3 2
184. CJNE @R1, #data, code_addr B7 3 2
185. CJNE R0, #data, code_addr B8 3 2
186. CJNE R1, #data, code_addr B9 3 2
187. CJNE R2, #data, code_addr BA 3 2
188. CJNE R3, #data, code_addr BB 3 2
189. CJNE R4, #data, code_addr BC 3 2
190. CJNE R5, #data, code_addr BD 3 2
191. CJNE R6, #data, code_addr BE 3 2
192. CJNE R7, #data, code_addr BF 3 2
Page 19 of 22
193. PUSH Data_addr C0 2 2
194. AJMP Code_addr C1 2 2
195. CLR Bit_addr C2 2 1
196. CLR C C3 1 1
197. SWAP A C4 1 1
198. XCH A, data_addr C5 2 1
199. XCH A, @R0 C6 1 1
200. XCH A, @R1 C7 1 1
201. XCH A, R0 C8 1 1
202. XCH A, R1 C9 1 1
203. XCH A, R2 CA 1 1
204. XCH A, R3 CB 1 1
205. XCH A, R4 CC 1 1
206. XCH A, R5 CD 1 1
207. XCH A, R6 CE 1 1
208. XCH A, R7 CF 1 1
209. POP Data_addr D0 2 2
210. ACALL Code_addr D1 2 2
211. SETB Bit_addr D2 2 1
212. SETB C D3 1 1
213. DA A D4 1 1
214. DJNZ Data_addr, code_addr D5 3 2
215. XCHD A, @R0 D6 1 1
216. XCHD A, @R1 D7 1 1
217. DJNZ R0, code_addr D8 2 2
218. DJNZ R1, code_addr D9 2 2
219. DJNZ R2, code_addr DA 2 2
220. DJNZ R3, code_addr DB 2 2
221. DJNZ R4, code_addr DC 2 2
222. DJNZ R5, code_addr DD 2 2
223. DJNZ R6, code_addr DE 2 2
224. DJNZ R7, code_addr DF 2 2
225. MOVX A, @DPTR E0 1 2
226. AJMP Code_addr E1 2 2
227. MOVX A, @R0 E2 1 2
228. MOVX A, @R1 E3 1 2
229. CLR A E4 1 1
230. MOV A, data_addr E5 2 1
231. MOV A, @R0 E6 1 1
232. MOV A, @R1 E7 1 1
233. MOV A, R0 E8 1 1
234. MOV A, R1 E9 1 1
235. MOV A, R2 EA 1 1
236. MOV A, R3 EB 1 1
237. MOV A, R4 EC 1 1
238. MOV A, R5 ED 1 1
239. MOV A, R6 EE 1 1
240. MOV A, R7 EF 1 1
241. MOVX @DPTR, A F0 1 2
Page 20 of 22
242. ACALL Code_addr F1 2 2
243. MOVX @R0, A F2 1 2
244. MOVX @R1, A F3 1 2
245. CPL A F4 1 1
246. MOV Data_addr, A F5 2 1
247. MOV @R0, A F6 1 1
248. MOV @R1, A F7 1 1
249. MOV R0, A F8 1 1
250. MOV R1, A F9 1 1
251. MOV R2, A FA 1 1
252. MOV R3, A FB 1 1
253. MOV R4, A FC 1 1
254. MOV R5, A FD 1 1
255. MOV R6, A FE 1 1
256. MOV R7, A FF 1 1
Page 21 of 22
Review Questions for module 2:
Page 22 of 22