Summary of Quick Memory Methods for 51 Microcontroller Instructions

MCS-51 refers to a series of microcontrollers produced by the American company INTEL. This series of microcontrollers includes several varieties, such as 8031, 8051, 8751, 8032, 8052, 8752, etc., among which the 8051 is the earliest and most typical product.

When learning about microcontrollers, in addition to understanding the internal functions, memory allocation, and I/O interfaces, one should also master its instruction system. The MCS-51 has a total of 111 instructions, and we will introduce the methods we have summarized for quickly memorizing MCS-51 instructions for your reference.

As we all know, assembly language instructions consist of two parts: opcode and operand. 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, @Ri, etc. Here we will first introduce the mnemonic symbols and their related memory methods.1. Mnemonic Memory Methods1. Tabular Listing MethodGroup the 44 instruction mnemonics into five categories based on functionality and list them for memory. This part is omitted; readers are encouraged to summarize themselves.2. English Restoration MethodThe opcode mnemonics of the microcontroller are abbreviations of the functions in English. Restoring the abbreviations to their original English words, and comparing them with Chinese, helps 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 Not Equal 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 MethodThe 44 instruction mnemonics of the microcontroller can be divided into five major categories based on their instruction functions, each of which can be grouped into 2-3 groups based on similar functions. This way, breaking them down into smaller parts allows for quicker memorization. 1) Data Transfer Group 2) Addition and Subtraction Group: MOV Internal Data Transfer, ADD Addition, MOVC Program Memory Transfer, ADDC Carry Addition, MOVX External Data Transfer, SUBB Carry Subtraction 3) Logic Operation Group 4) Subroutine Call Group: ANL Logic AND, LCALL Long Call, ORL Logic OR, ALALL Absolute Call, XRL Logic XOR, RET Subroutine Return.2. Memory Methods for Instructions1. Relevant Symbols for Instruction OperandsThe MCS-51 has six addressing modes: immediate addressing, direct addressing, register addressing, register indirect addressing, indexed addressing, and relative addressing. We must master their representation methods.

1) Immediate and Direct Address. ata represents an eight-bit immediate number, #data16 represents a sixteen-bit immediate number, data or direct represents a 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 mnemonic symbols of the instructions and mastering the representation methods for the instruction operands of different addressing modes lays the 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 logic operation instructions, 17 control transfer instructions, and 17 Boolean bit operation instructions. Within each category of instructions, based on their functions, capturing the different combinations of source and destination operands, along with the following methods, can lead to complete memorization. We agree that the 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, thus allowing us to remember the 15 MOV instructions. For example, with accumulator A as the destination operand, the following four instructions can be written: MOV A, #data/direct/A/Rn/@Ri. Similarly, 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 MethodThe diagram memory method uses graphics and arrows to represent the relationships between destination and source operands for instructions that have the same or similar operational functions but different operands. For example, the array transfer instructions composed of mnemonics MOV, MOVX, MOVC can be memorized with the help of diagrams 1 and 2. The four instructions formed by the mnemonic CJNE can also be represented using the diagram method, 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 logic operation instructions formed by (ANL, ORL, ARL), the four rotate instructions related to A can also be represented using the diagram method; readers are encouraged to draw their own for memory.3. Similar Function Classification MethodIn 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 groups such instructions together for memorization; by remembering one of them, the others can also be remembered. For example, the twelve addition and subtraction instructions, as well as the eighteen logic instructions, are listed as follows. 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 has similar functions, and their operands are the same. Other instructions like increment (INC) and decrement (DEC) can also be handled this way.4. Mnemonic Memory Method

For some instructions, we can compile related functions into a concise phrase for memorization. For example, for the PUSH direct and POP direct instructions, beginners often find it difficult to distinguish the changes in the stack SP. Therefore, a phrase is compiled as follows: (The content of SP) plus 1 (the content of direct) is pushed onto the stack, (the content of SP) pops (to the direct unit) and SP is decremented by 1. Similarly, for multiplication instructions, the storage of the product, and for division instructions, the storage of the dividend, divisor, and quotient can also be compiled into mnemonic phrases as follows:

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 for readers, and I believe that readers can find their own suitable methods for memorization during their learning process. However, having good methods is not enough; practice is also necessary. Therefore, read the example problems in books and programs written by others, and then combine them with practical programming. Only in this way can you better and more quickly master the microcontroller instruction system. It is recommended that

At the beginning of learning microcontrollers, you must understand some digital circuits. If you are still unclear about the general concepts in digital circuits, it is best to review before learning microcontrollers. Next, it is advisable to select one type of microcontroller for study, as there are many types of microcontrollers currently available, and their structures and instructions are not the same. If you study one for two days and another for two days, you will often end up with too much to digest.

It is recommended that you start with the 8051 microcontroller, as there are many books, materials, and equipment available on the 8051. Although PIC and AVR and other types of microcontrollers have their advantages, the current books, materials, and component supply are not ideal and may not be suitable for beginners. If you are not concerned about these, then it is also acceptable to choose the latter for study. The reason we suggest starting with the 8051 microcontroller is that there are many derivatives of the 8051 family, such as ATMEL’s AT89C51 series microcontroller, which is fully compatible with the MSC-51 8051 series (that is, the instructions, pins, internal structure, and usage of AT89C51 are the same as MSC-51). It is not only compatible but also has many innovations, such as its program memory being electrically erasable and writable, making it a minimal system without needing the previously mentioned 373 and EPROM components; thus, the circuit connections and circuit board fabrication during experiments are relatively easy. Moreover, its price is relatively low, allowing you to use the microcontroller for both learning and product development. Of course, the AVR series also has these characteristics, while PIC and other series are less ideal in this regard. When purchasing books on microcontrollers, it is best if you can understand the front part of the book while not understanding the back part. If you do not understand both parts, it is best not to buy the book, as it will not be of much use in a short time. Of course, if you are not buying the book as a reference, you do not have to buy a book that you understand both front and back, as it may be too shallow for you. Focus on principle books primarily. Secondly, you can purchase some application-related books for reference. Electronic technology itself is inseparable from experiments; it is difficult to understand its principles and learn microcontroller development solely by reading. You should acquire relevant microcontroller chips, programmers, experimental boards, and the related software to learn effectively through a combination of reading and experimentation. Due to being a beginner, it is not possible to purchase many expensive devices. It is recommended to use microcontroller chips whose program memory can be repeatedly erased and written, such as the AT89C series or AVR series. This way, you will have no worries during learning and programming.

Now let’s discuss the steps of microcontroller development. To make the microcontroller complete a task according to your wishes (ideas), you must first write the program for it to use. The program for the microcontroller should be written in a language that the microcontroller can recognize; otherwise, you will be playing the “stone” with a “ball”. Currently, assembly and C languages are popular; assembly language allows precise control of every step the microcontroller takes, while C language focuses on the result without needing to worry about each specific step of the microcontroller.

It is customary to learn assembly language first and then C language, as this allows for a deeper understanding of the microcontroller. Moreover, even when programming in C, assembly statements may need to be embedded for precise control. Of course, some may start with C language and then learn assembly later. If you have learned Turbo C for computers, starting with microcontroller C may be faster.

The microcontroller program is written as a pure text file in a text editor, similar to how we write plans in Chinese in Windows Notepad, sequentially writing down what the microcontroller needs to do according to the syntax of the language used. When encountering “some things” that are repetitive, specify where there is already an explanation (jump). In normal arrangements, if other unexpected events occur, a segment of emergency event handling plan (interrupt) must be written… Finally, the file’s extension should match the name required by the language used; our Chinese articles are generally saved as *.txt extensions, while assembly language files usually have the extension *.asm; some development systems have their own regulations, such as the Keil C51 development system, where the assembly program is saved as *.a51; of course, the Keil C51 development system also has its own editor, so there is no need to use Windows Notepad. Whether we use assembly language or C language to write the program, it is just for our viewing; this program must be translated (compiled) into code that the microcontroller can recognize through the corresponding software for that language. The code that the microcontroller can recognize must be burned (programmed) into the microcontroller’s program memory, so that the microcontroller can work according to your “plan” in the actual circuit. For the 8051 series microcontroller, the Keil C development system has functions for editing, compiling, and simulating C language programs, as well as editing, compiling, and simulating assembly language programs. For beginners, the programs they write are bound to have syntax errors or other non-standard statements, as the error messages during compilation in Keil C are in English and may be difficult to understand. If using assembly, a macro assembler compiler ASM51 can be used under DOS; it can provide error messages in Chinese, and the comment sections of your source program can also use Chinese, making it easier for you to maintain the program in the future. The compiled code generally has the extension *.hex or *.bin; this code file must be sent to the microcontroller in the circuit for it to work according to your “plan”. The tool for sending this code file to the microcontroller is the programmer, which generally connects to the computer via parallel or serial ports, along with the corresponding service program; after properly connecting the computer and programmer, run its service program, first select the model of the microcontroller to be programmed, then load the previously obtained code file, and finally use the programmer to burn this code file into the microcontroller. At this point, the process of microcontroller development is roughly complete. Of course, you cannot expect to write your “plan” perfectly in the microcontroller’s language on the first try (just as our plans in reality often require modifications). This requires repeatedly modifying the source program, recompiling, burning it into the microcontroller, and repeatedly testing the microcontroller in the circuit. Since the microcontroller takes a very short time to execute each statement, sometimes you cannot obtain intermediate results or determine where the program has gone wrong. In this case, you can use software simulation methods to let the program execute step by step. After each step, check the changes in various key data in the microcontroller to find errors or statements that did not execute according to your “plan”, thus achieving the purpose of debugging. If funding is not an issue, you can also purchase a microcontroller emulator, which can replace the microcontroller in the actual circuit and debug step by step under computer control. In fact, both software simulation (emulation) and hardware emulation serve far more functions than just what is mentioned here.

Summary of Quick Memory Methods for 51 Microcontroller Instructions

Leave a Comment