Through the previous articles, the 111 basic instructions in the single-chip microcomputer are used flexibly through the corresponding examination questions and exercises. This article summarizes and expands the previous article.
First, the instruction has three attributes of function, time and space.
Function attribute: means that each instruction corresponds to a specific operation function.
Time attribute: refers to the time required for the execution of an instruction, generally expressed in machine cycles.
Space attribute: refers to the number of bytes occupied by the storage of an instruction in the program memory.
Second, classification
1, according to the instruction space attributes:
(1) single-byte instructions (49)
(2) double-byte instructions (45)
(3) three-byte instructions (17)
2, according to the instruction time attributes:
(1) 1 machine cycle instruction (64)
(2) 2 machine cycle instructions (45)
(3) 4 machine cycle instructions (2)
3. According to the instruction function attribute:
(1) data transfer instruction ( 29)
(2) Arithmetic operation instructions (24)
(3) Logic operation instructions (24)
(4) Control transfer instructions (17)
(5) Bit operation instructions (17)
Three, addressing mode
(symbol Instruction writing format: Operation mnemonic [destination operand] [, source operand] [; comment])
1, immediate addressing
2, direct addressing
3, register addressing
4, register indirect addressing
5, index search Address (base address register DPTR / PC + index register A inter-address addressing):
MOVC A, @ A + DPTR
MOVC A, @ A + PC
JMP A, @ A + DPTR
6, relative addressing:
destination address = address of transfer instruction + number of transfer instruction bytes + rel
7, bit addressing
4, internal RAM map, register address and Reset value
Fifth, some difficult to understand and often explain instruction instructions
1, PUSH, POP instructions
Stack definition: In the 51 MCU series internal data storage area is set to an area that operates according to the principle of last in first out . One end of the stack area is fixed and becomes the bottom of the stack, and the other end is active and becomes the top of the stack. (Note: The stack area grows upwards)
(1) PUSH
PUSH direct instruction ; (SP) + 1- > SP, (direct)-> (SP)
Resolution : When executing this instruction, first set the stack pointer SP + 1 , And then send the contents of the direct to the internal RAM unit indicated by the SP.
Examples:
设(SP)=50H,(A)=30H,(B)=60H,执行如下指令:
PUSH ACC
PUSH B
后,试回答:(51)= ,(52H)= ,(SP)=
答案:
(51)=30H ,(52H)=60H,(SP)=52H
(2) Stack instruction POP
POP direct; ((SP))-> (direct), (SP) -1-> SP
analysis : When this instruction is executed, the content in the top unit of the stack indicated by SP is first sent into In the direct byte, the content of the SP is decremented by 1 and assigned to the SP.
Examples:
设(SP)=52H,(52H)=30H,(51H)=60H,执行如下指令:
POP DPL
POP DPH
后,试回答:(DPTR)= ,(SP)=
答案:
(DPL)=30H ,(DPH)=60H ,(DPTR)=6030H ,(SP)=50H
Note: PUSH, POP instruction operands are direct addresses, not registers, for example: PUSH R0 this instruction error (the following error will occur during program compilation: error A22: EXPRESSION TYPE DOES NOT MATCH INSTRUCTION )
2, RET instruction
subroutine Return instruction RET, this instruction does not affect the status flag bit, the execution process:
RET ;((SP))-> PC(15-8), (SP)-1 ->SP
;((SP))-> PC(7-0), (SP)-1 ->SP
Comprehensive test questions: The
following questions fully investigate the understanding of PC, stack and RET
设(30H)=51H,执行以下指令后,
ORG 0000H
MOV 64H,#00
MOV 65H,#00
ACALL FUC
MOV A,30H
SWAP A
MOV 30H,A
HALT:SJMP HALT
FUC:
MOV SP, #66H
MOV A, #51H
MOV B, #52H
PUSH ACC
PUSH B
POP ACC
POP B
RET
(SP)= ,(30H)= ,(A)= ,(B)= ,P= ,Cy= ,Ac= ,OV=
答案:
(SP)= 64H ,(30H)=15H ,(A)= 15H ,(B)= 51H ,P=1 ,Cy=0 ,Ac=0 ,OV= 0
Sixth, the basic use of programming software KEIL
1, install the software (software download and installation process is omitted), after installation, as shown in Figure
2, open the software, click New Project-> New Project
3, click to enter, create a new file for storage Project, then enter the project name, click Save
4, select the MCU model in the pop-up interface, select AT89C51
5, click OK, in the pop-up dialog box, click Yes
6, create a new file, select file-> new file or Ctrl + N New
and then save (Ctrl + S), enter the file name, click Save (note the file suffix name format: C file is .c assembly file is .asm), here build assembly file
7, add the above as in the project Newly created file
Right-click on source group1, click add files to group in the pop-up dialog box… Option
8, click ALL files option for ALL files, find the newly created .asm file, double-click the file to add it to the project
9, in the source group Click .asm to start writing the program, and click the button to compile the program after writing.
10. Compile and generate the .hex file (this file is used to download to the MCU)
Step 1. Click the magic wand, as shown in the following figure.
Step 2, according to the following figure, check the option to generate .hex file
and then compile again.
By using a simple programming software, after the understanding of the exercises, can be verified by software simulation program to verify
the authentication method:
Step one, a good compilation compiled file, click below that is a second option or the third option
Step two, Ctrl + F5 for simulation debugging. The
red circle is (from left to right) in order to execute at full speed to the breakpoint, single-step execution, jump out of
single-step execution, you can view the value in the corresponding register through the left register, if you need to view a certain The value in the address, for example, look at the value in 30H, in the lower right Memory, and then enter d: 30H in Address to see the
supplement
. Enter the address value in the Memory window, the result is the content of the program code area. Because 51 uses a Harvard structure, program instruction storage and data storage are separated. To view the contents of various memory areas, just enter " letter: address " in the Address box to display the corresponding memory value. The letters can be C, D, I, X, which means: (both uppercase and lowercase)
C: code storage space
D: Directly address the on-chip storage space
I: indirect addressing on-chip storage space
X: Expanded external RAM space
If you enter "d: 0x30", you can display the contents of the directly addressable 30H storage space on the chip.
You can also use the right-click "Modify Memory" option to modify the contents of the specified memory.