Common Pseudo Instructions Used in Microcontrollers

When writing code for microcontrollers, there are always some instructions that act like “unsung heroes”—they are not the “real instructions” executed directly by the CPU, but they can make the code more concise and efficient. These “pseudo instructions” are like “shortcuts” in programming; if used well, they can save a lot of effort! Today, let’s discuss the 5 most commonly used pseudo instructions in microcontrollers in simple terms, so you can directly “copy the homework”!

Common Pseudo Instructions Used in Microcontrollers

1. ORG

Function: Specifies the starting address of the program or data.

Scenario: When the microcontroller starts, the CPU executes code from a fixed address (e.g., 0x0000). ORG tells the assembler, “My code starts storing from here.”

Analogy: Like marking page numbers in a book, telling the reader, “Chapter 1 starts on page 5.”

2. EQU

Function: Replaces constant values with symbols.

Scenario: When defining port numbers or register addresses, writing PORTA EQU 0x20 is more readable than writing 0x20 each time, and it only needs to be changed in one place.

Analogy: Like giving a nickname to a friend, “Old Zhang” is easier to call than “the one in the blue clothes.”

3. DB/DW

Function: Defines data of byte (DB) or word (DW) type.

Scenario: When initializing lookup tables or strings, using DB 0x01,0x02,0x03 directly stores a series of data, which is more efficient than using multiple MOV instructions.

Analogy: Like packing items into a backpack, DB is for small items (bytes), while DW is for larger items (16-bit data).

4. END

Function: Marks the end point of the program.

Scenario: The assembler stops translating when it reads END; any code written afterwards will not be executed, preventing “extra code” from interfering.

Analogy: Like putting a period at the end of a letter, telling the reader, “The letter is finished.”

5. NOP

Function: Inserts a no-operation instruction (occupying 1 machine cycle).

Scenario: Used for delays, aligning instruction cycles, or as placeholders for future modifications, such as “leave this space for later functionality.”

Analogy: Like saying “um…” during a conversation, pausing temporarily without affecting the overall flow.

This article is an original piece by Yiy Education; please indicate the source when reprinting!

Leave a Comment