Everyone knows that assembly language instructions consist of an opcode and operands. The MCS-51 uses assembly language instructions, which have a total of 44 opcode mnemonics and 33 functions, with operands such as #data, direct, Rn, and @Ri. Here, we will first introduce mnemonic symbols for instructions and methods for memorizing them.
1. Mnemonic Symbol Memory Methods
1. Tabular Listing Method
Classify the 44 instruction mnemonics into five categories based on their functions, and memorize them by listing.
2. English Restoration Method
The opcode mnemonics of the microcontroller are English abbreviations of the function of the instruction. Restoring the abbreviation to its original English text and comparing it with Chinese helps to understand the meaning of the mnemonics, thus enhancing memory. For example:
Increment INC – Increment Decrement DNC – Decrement
Short Jump SJMP – Short jump Long Jump LJMP – Long jump
Compare Jump CJNE – Compare jump not equal
Absolute Jump AJMP – Absolute jump No Operation NOP – No operation
Exchange XCH – Exchange Addition ADD – Addition
Multiplication MUL – Multiplication Division DIV – Division
Rotate Left RL – Rotate left Rotate Left Carry RLC – Rotate left carry
Rotate Right RR – Rotate right Rotate Right Carry RRC – Rotate right carry
3. Functional Module Memory Method
The 44 instruction mnemonics of the microcontroller can be divided into five major categories based on their functional instructions, and each category can further be grouped into 2-3 groups based on similar functions. This way, breaking them down into smaller parts allows for easier memorization.
1) Data Transfer Group. 2) Addition and Subtraction Group
MOV Internal Data Transfer ADD Addition
MOVC Program Memory Transfer ADDC Addition with Carry
MOVX External Data Transfer SUBB Subtraction with Borrow
3) Logical Operation Group. 4) Subroutine Call Group.
ANL Logical AND LCALL Long Call
ORL Logical OR ALALL Absolute Call
XRL Logical XOR RET Subroutine Return
2. Instruction Memory Methods
1. Relevant Symbols of Instruction Operands
The MCS-51 has six addressing modes: immediate addressing, direct addressing, register addressing, register indirect addressing, indexed addressing, and relative addressing. We must master the representation methods.
1) Immediate and Direct Address. Data represents an 8-bit immediate value, #data16 represents a 16-bit immediate value, data or direct represents direct address.
2) Rn(n=0-7), A, B, CY, DPTR register addressing variables.
3) @R0, @R1, @DPTR, SP represent register indirect addressing variables.
4) DPTR+A, PC+A represent indexed addressing variables.
5) PC+rel (relative quantity) represents relative addressing variables.
Remembering the mnemonics of instructions and mastering the representation methods of instruction operands for different addressing modes lays a foundation for memorizing assembly instructions. Although there are many MCS-51 instructions, they can be categorized into five types: 28 data transfer instructions, 24 arithmetic operation instructions, 25 logical operation instructions, 17 control transfer instructions, and 17 Boolean bit operation instructions. Within each category of instructions, we can grasp the different combinations of source and destination operands based on their functions, supplemented by the following methods, to achieve complete memorization.
We agree that possible destination operands are represented in the order of (#data/direct/A/Rn/@Ri).
For the MOV instruction, the destination operands are written in the order of A, Rn, direct, @Ri, allowing us to memorize 15 instructions of MOV. For example, using accumulator A as the destination operand, we can write out the following four instructions.
MOV A, #data/direct/A/Rn/@Ri
Continuing in this manner, we can write out other instructions.
MOV Rn, #data/direct/A
MOV direct, #data/direct/A/Rn/@Ri
MOV @Ri, #data/direct/A
2. Instruction Diagram Memory Method
The diagram memory method uses graphics and arrows to represent the relationships of destination and source operands for instructions with the same or similar functions but different operands. For example, the array transfer instructions composed of mnemonics MOV, MOVX, and MOVC can be aided by diagrams 1 and 2 for memorization.
The four instructions formed by the mnemonic CJNE can also be represented using diagrams, as shown in diagram 3.
CJNE A, #data, rel CJNE A, direct, rel
CJNE @Rn, #data, rel CJNE @Ri, #data, rel
Additionally, for the 18 logical operation instructions formed by (ANL, ORL, ARL) and the four rotate instructions related to A, the diagram memory method can also be used; readers are encouraged to draw their own diagrams for memorization.
3. Similar Function Classification Method
In the MCS-51 instructions, we find that some instructions have different opcodes but similar functions, while their operands are completely the same. The similar function classification method involves grouping such instructions together for memorization; as long as one is remembered, the others will follow. For example, the twelve addition and subtraction instructions, as well as the eighteen instructions for AND, OR, and NOT, are listed below.
ADD/ADDC/SUBB A, #data/direct/Rn/@Ri
ANL/ORL/XRL A, #data/direct/Rn/@Ri
ANL/ORL/XRL direct, #data/a
Each row of instructions above has similar functions, and their operands are the same. Other instructions, such as increment (INC) and decrement (DEC) can also be handled in this manner.
4. Mnemonic Memory Method
For some instructions, we can compile related functions into a concise sentence for memorization. For instance, the two instructions PUSH direct and POP direct. Beginners often struggle to understand the changes in the stack pointer SP, so we can create the following sentence: (Content of SP) plus 1 (Content of direct) goes into the stack, (Content of SP) pops out (to the direct unit) and SP decreases by 1. Similarly, for multiplication instructions regarding where the product is stored, or division instructions regarding the dividend, divisor, and quotient, we can create mnemonic phrases for memorization:
MUL AB High byte of product (stored in) B, Low byte of product (stored in) A.
DIV ABA divided by B, Quotient (stored in) A, Remainder (stored in) B.
The methods introduced above for quickly memorizing microcontroller instructions are hoped to serve as a starting point. I believe readers will find suitable methods for memorization during their learning process. However, having good methods is not enough; practice is also necessary. This means reading examples from books and programs written by others, and then combining that with writing some programs on your own. Only by doing so can you better and more quickly master the microcontroller instruction system.