51 MCU Principles and Assembly Tutorial (II) Common Assembly Instructions, Data Transfer Instructions and Addressing Modes

Publisher:MysticDreamerLatest update time:2022-09-07 Source: csdn Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Internal data transfer instructions

1. MOV instruction

① MOV R0 , #20H

  # is followed by an immediate number, which should be distinguished from the address. 20H is a hexadecimal number. This sentence means to send the number 20H to register R0. Direct addressing

② MOV 30H , @R0

  The number in R0 is given to the address 30H with this digital address.

③MOV C, 20.4H

  Bit addressing, this C is the highest bit in the PSW program status word, CY is the carry bit, and the borrow bit.


2. Access external RAM memory

① MOV DPTR, #1234H

  DPTR is divided into DPH and DPL (high 8 bits and low 8 bits), which are stored in the SFR of the internal RAM. The function of this sentence is to give the immediate value to DPTR.

② MOVX A, @DPTR

  The purpose of this sentence is to take out the number pointed to by DPTR from the external RAM and give it to A, reading from the external memory.

  Read operation process (automatically completed): the value in DPH is sent to A15-A8 through the address bus, and then the value in DPL is sent to P0 port. ALE sends a latch signal (a high pulse signal) and the latch changes to the level of P0 port. After that, RD sends another read signal (a low level pulse), and the data is sent to P0 port through the data bus, and finally to A. Here, P2 port acts as the high eight bits of the address, and P0 port is time-division multiplexed through a latch, acting as both the low eight bits of the address and the digital bit.

insert image description here

③INC DPTR

  Function: DPTR plus one

④MOVX @DPTR, A

  Write the value of A to the address corresponding to DPTR

⑤MOV R0, #44H

  Function: Store 44H in R0

⑥MOVX A, @R0

  Function: Read external RAM


Key point: MOVX requires a 16-bit address when operating externally. If there are only 8 bits, the lower eight bits of the address will be retained while the higher eight bits will be kept.

  There are only three ways to access external RAM: ①DPTR ②R0 ③R1

  The address can only be set through these three. Using R0 and R1 is called page addressing, and it can only determine port P0, which is the lower eight bits of the address.

  256 x 256 = 65536

  Page Address within the page


3. Get data from ROM

  ROM is a read-only memory that can only perform read operations but not write operations.

  There are only two reading methods: ① MOVC A, @A+DPTR ② MOVC A, @A+PC

  DPTR and PC are both 16 bits, and the accessible range is 64K

  There are two methods:

1. Remote meter query

  MOV A, #00H

  MOV DPTR, #1234H

  MOVC A,@A+DPTR

  By assigning a value to DPTR, a table lookup can be performed at any position.

2. Short-range table lookup

  MOV A,#00H

  MOVC A, @A+PC

  MOV 30H, A

  Because A is 8 bits, it can only be changed at the current PC position.


2. 7 addressing methods

1. Immediate addressing

  MOV A, #00H

  MOV 30H, #33H

  MOV DPTR, #1234H

2. Direct addressing

  MOV A, 3AH

  MOV 30H, 33H is translated into machine code 85 33 30

  Direct addressing accesses the SFR address

3. Register addressing

  MOV A ,R0

  MOV A,R1

  INC R1

4. Register indirect addressing (only R0 and R1 can be used)

  MOV A,@R0

  MOV A ,@R1

  INC @R1


  Read external RAM

  MOVX A, @R0

  MOVX A, @R1

  Writing external ROM

  MOVX @R0, A

  MOVX@DPTR,A


  MOVX A, @DPTR

  MOVX@DPTR,A

5. Relative addressing

  JC 80H 80H–>rel

  Function: Jump if C is 1 rel: 8-bit signed offset address

  PC destination = PC current + rel

6. Indexed addressing

  MOVC A, @A+DPTR

  MOVC A, @A+PC

  JMP @A+DPTR

7. Bit addressing

  MOV C, 00H

  MOV ACC.5 C

  CPL C

Reference address:51 MCU Principles and Assembly Tutorial (II) Common Assembly Instructions, Data Transfer Instructions and Addressing Modes

Previous article:51 MCU Principle and Assembly Tutorial (I) 51 MCU Structure and Principle
Next article:51 MCU - Serial Communication

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号