Subroutine call and return instructions
In program design, common program segments with certain functions are usually compiled into subroutines. When the subroutine is needed, the CALL instruction is called, and a subroutine return instruction RET is arranged at the end of the subroutine so that after the subroutine is executed, it can return to the main program to continue execution.
1. Call instruction CALL
Before the program transfer occurs, the current value of PC is pushed into the stack, and then the subroutine entry address is sent to PC, so that the CPU switches to executing the subroutine.
instruction | illustrate |
---|---|
CALL rel | By default, this is equivalent to ACALL rel |
ACALL addr11 | addr11 is sent to PC10~PC0, while PC15~PC11 remain unchanged, the transfer range is 2KB |
LCALL addr16 | addr16 is loaded into PC, transfer range 64KB |
2. Subroutine return instruction RET** The subroutine return instruction pops the contents of the two adjacent cells on the top of the stack and sends them to the PC, subtracts 2 from the contents of SP, and the program returns to the instruction pointed to by the PC value. The RET instruction is usually placed at the end of the subroutine so that the program can return from the subroutine to the main program.
3. Interrupt return instruction RETI** The RETI instruction has the same function as the RET instruction, which is to make the subroutine return to the main program. However, the RETI instruction does one more thing than the RET instruction, that is, before the main program returns, the instruction will also clear the corresponding interrupt flag to indicate that the interrupt has been responded to.
4. No operation instruction NOP** No operation is also a CPU control instruction. It does not have the function of transferring the program. It only consumes one machine cycle, that is, PC+1 at this time. It is often used for program waiting or time delay. ``` ******************************************************************/ *
【Course 4】 ****Application of MCU Assembly Instruction System*********** *
【Description】 ****Through this example, you can understand the assembly instruction system of the microcontroller and write programs*
【Description】 ****Add two immediate numbers FCH and 52H******************************************************************/ ORG 0000H Start: MOV A,#0FCH ;Calculate FCH+52H=? MOV R0,#52H ADD A,R0 JC L1 ;Judge CY, if CY=1, jump to L1 and execute MOV 30H,#00H JMP L2 L1: MOV 30H,#01H L2: MOV 31H,A
MOV A,#0FCH ANL A,R0 ; Calculate the AND of two numbers MOV P0,A MOV A,#0FCH ORL A,R0 ; Calculate the OR of two numbers MOV P1,A MOV A,#0FCH XRL A,R0 ; Calculate the XOR of two numbers MOV P2,A MOV A,#0FCH CPL A ; Negate the FCH number MOV P3,A RL A ; Shift left 1 bit RL A ; Shift left 1 bit RL A ; Shift left 1 bit RL A ; Shift left 1 bit MOV P3,A END
Previous article:2: The first 51 single-chip microcomputer assembly experiment
Next article:IV: Output application of IO port
Recommended ReadingLatest update time:2024-11-15 08:45
- Popular Resources
- Popular amplifiers
- Sensor Principle and Application Circuit Design (Edited by Chen Shuwang, Song Lijun, Xu Yunfeng)
- Detailed explanation of big data technology system: principles, architecture and practice (Dong Xicheng)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- What will happen if the servo motor inertia is insufficient?
- How to select parameters for servo motor inertia size
- The difference between the servo motor moment of inertia and the load moment of inertia
- How to calculate the inertia of servo motor and reducer
- What is the difference between a servo press and a normal press?
- Analysis of ZigBee Terminal Direct Join Method
- EEWORLD University Hall----Mentor PADS VX2 four-layer router
- LLC formula derivation, loop compensation transfer function derivation calculation and simulation
- EEWORLD University Hall ---- Introduction to Deep Learning
- [FreeRTOS check-in station 4 opens] Inter-task communication, closing time is August 23
- After the PWM frequency of STM32 reaches 500KHZ, can it be increased or decreased by 1KHZ?
- ESP32-S2 Development Pitfalls—by RCSN
- Motor drive MOS reasons
- [Technical Discussion] How to troubleshoot electromagnetic interference in wireless communications?
- STM32 replacement note: It is easy to replace domestic chips!