Introduction to assembly instructions

1. Classification of assembly instructions

There are totally 7 addressing modes and 111 instructions in assembly instructions!

  • Number of bytes
    • Single-byte instructions: 49
    • Double-byte instructions: 46
    • Three-byte instructions: 16
  • calculating speed
    • Single cycle instructions: 65
    • Two-cycle instructions: 44
    • Four-cycle instructions: 2
  • Features
    • Data transmission category: 29
    • Arithmetic operations: 24 items
    • Logical operations: 24 items
    • Control transfer category: 17
    • Bit operation category: 17

2. Compiled instruction format

[Label:] mnemonic [operand] [; comment]

  • Label: indicates the location of the instruction, which is equivalent to marking the location of the instruction stored in ROM;
  • Mnemonic: This is an essential part of an instruction;
  • Operand: there can be multiple or none, it needs to be determined according to the instruction;
  • Note: It is used to explain the meaning of the written statement, or some description of the program, which can be given as needed.

3. Description of common symbols in assembly instructions

  • Rn: One of the registers R0...R7 in the working register
  • Ri: Register R0 or R1 in the working register
  • #data: 8-bit immediate data
  • #data16: 16-bit immediate data
  • direct: the address of the on-chip RAM or SFR (8 bits)
  • @: Indirect addressing register
  • Bit: Bit address that can be bit-addressed in the on-chip RAM or SFR
  • addr11: 11-bit destination address
  • addr16: 16-bit destination address
  • Rel: 8-bit address offset in complement
  • $: The address of the first byte of the current command
  • X: Direct address or register of on-chip RAM
  • (X): The content in the corresponding address unit
  • ←: The content on the right of the arrow is sent to the unit on the left of the arrow
  • →: The content on the left of the arrow is sent to the unit on the right of the arrow

4. Data transfer instructions (29 items)

Instruction mnemonic

MOV、MOVX、MOVC、XCH、XCHD、SWAP、PUSH、POP

Instructions with accumulator as the destination operand (4 items)

MOV A, Rn    		;Rn→A
MOV A, direct		;(direct)→A
MOV A, @Ri	   		;(Ri)→A
MOV A, #data			;data→A

Instructions with register Rn as the destination operand (3 items)

MOV Rn, A			;A →Rn	
MOV Rn, direct		 ;(direct)→Rn
MOV Rn, #data		;data→Rn

Instructions with direct address as the destination operand (5 items)

MOV direct, A		;A→(direct)
MOV direct, Rn		;Rn→(direct) 	
MOV direct1,direct2	
MOV direct, @Ri		;(Ri) →(direct) 
MOV direct, #data 	;data→(direct)

Instructions with indirect address as the destination operand (3 items)

MOV @Ri, A          ;A →(Ri)
MOV @Ri, direct		;(direct) →(Ri)
MOV @Ri, #data		;data →(Ri)

Sixteen-digit transmission instruction (1 item)

MOV DPTR, #data16

8051 is an 8-bit machine, which is the only 16-bit immediate transfer instruction.
Function: Send a 16-bit immediate data to DPTR. The upper 8 bits are sent to DPH, and the lower 8 bits are sent to DPL.

Data transfer instructions between accumulator A and off-chip RAM (4)

MOVX A, @Ri
MOVX @Ri, A
MOVX A, @DPTR
MOVX @DPTR, A

​ In 51, only the A accumulator can deal with the external memory RAM. All data that needs to be sent to the external RAM must be sent through A, and all data in the external RAM to be read must also be read through A.
​ Here we can see the difference between internal and external RAM. Data can be transferred directly between internal RAM, but not external.

Read program memory instructions (2 items)

MOVC A, @A+DPTR
MOVC A, @A+PC

This group of instructions is to send the number in ROM to A. This group of instructions is also called table look-up instruction. This instruction is often used to look up a table that has been prepared in ROM. Explanation: The result of the search is placed in A. Therefore, the value in A is different before and after this instruction is executed.

Stack operation (2 items)

PUSH  direct    ;SP ← SP+1,(SP) ← (direct)
POP   direct    ;(direct) ← (SP), SP←SP-1

The first is a push instruction, which is to send the contents of direct to the stack; the
second is a pop instruction, which is to send the contents of the stack back to direct.

Exchange instructions (5 items)

XCH   A, Rn	    	;A←→Rn
XCH   A, direct   	;A←→(direct)
XCH   A, @Ri		;A←→(Ri)
XCHD  A, @Ri	   	;A.3~A.0←→(Ri).3~(Ri).0
SWAP  A		    	;A.3~A.0←→A.7~A.4

5. Arithmetic operation instructions (24 items)

Mnemonic

ADD、ADDC、INC、SUBB、DEC、DA、MUL、DIV

Addition instruction

1. Addition instructions without carry bit (4 items)

ADD A,#data 		;A+data→A
ADD A,direct 		;A+(direct )→A
ADD A,Rn 		    ;A+Rn→A
ADD A,@Ri 			;A+(Ri)→A

2. Addition instructions with carry bit (4 items)

Addition instructions with carry bit are often used in multi-byte addition instructions

ADDC A,Rn			;A+Rn+CY→A
ADDC A,direct		;A+(direct )+CY→A
ADDC A,@Ri			;A+(Ri)+CY→A
ADDC A,#data		;A+data+CY→A

3. Add 1 instruction (5 items)

INC  A			;A+1→A,影响P标志
INC  Rn			;Rn+1→Rn
INC  direct		;(direct)+1→(direct)
INC  @Ri		;((Ri))+1→((Ri))
INC  DPTR		;DPTR+1→DPTR

4. Decimal adjustment instruction (1 item)

When performing BCD code addition, it is used to automatically correct the result of BCD code addition following the ADD and ADDC instructions.

DA  A

Example: A = 0001 0101 BCD (representing 15 in decimal)

ADD  A,#8	;执行完之后,A = 1DH
DA  A		;调整后,A = 23H

Subtraction instruction

1. Subtraction instructions with borrow (4 items)

SUBB A,Rn	     	;A-Rn-CY→A
SUBB A,direct 		;A-(direct )-CY→A
SUBB A,@Ri	     	;A-(Ri)-CY→A
SUBB A,#data		;A-data-CY→A

Guess you like

Origin blog.csdn.net/qq_43580193/article/details/108300852