3: 51 assembly instruction system

Publisher:zdf1966Latest update time:2019-08-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

instructionillustrate
CALL relBy default, this is equivalent to ACALL rel
ACALL addr11addr11 is sent to PC10~PC0, while PC15~PC11 remain unchanged, the transfer range is 2KB
LCALL addr16addr16 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


[1] [2]
Reference address:3: 51 assembly instruction system

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

Hall sensor accurate speed measurement based on 51 single chip microcomputer timer 0 timer counter 1 count
#include reg52.h #include intrins.h #define uchar unsigned char #define uint unsigned int      sbit RW=P2^6; //define LCD1602 liquid crystal display read and write port          sbit RS=P2^5; //define LCD1602 liquid crystal display data command terminal sbit EN=P2^7; //define LCD1602 liquid crystal display enable te
[Microcontroller]
Hall sensor accurate speed measurement based on 51 single chip microcomputer timer 0 timer counter 1 count
8051 single chip microcomputer TLC1549 data acquisition program source code
#i nclude stdio.h   #i nclude REGX51.H   #i nclude "iic.h"  #define uchar unsigned char  #define uint unsigned int  uint Timer_Pro_Flag=0;//0 for display processing, 1 for timing acquisition processing  sbit TEST_CAP_VOL_CRLT=P1^0;//used to control external relay  sbit PWM_Pin=P3^7;//PWM output  sbit IrDA_in_Pin=P1
[Microcontroller]
Keil C51 program debugging process
When writing programs with the MCS-51 microcontroller software Keil C51, debugging is often required. If you do not use this software frequently, it is easy to forget these debugging steps. Here is an example of "verifying that the delay function delay() makes its delay time 500ms" for future review. After the source
[Microcontroller]
Keil C51 program debugging process
51 MCU T2 timer application
Timer T2 has three working modes, among which MODE 2 is the baud rate generator. 1. Mode 2: Baud rate generator The baud rate of serial port modes 1 and 3 is calculated as follows: Baud rate bps = oscillator frequency freq/ 则:RCAP2=65536-(freq/32/bps) If freq = 11.0592MHZ, bps = 9600, then: RCAP2 = 65500
[Microcontroller]
Using 51 single-chip microcomputer to realize peripheral device interrupt
There are 5 peripheral devices, EX1~EX5, all of which need interrupts . Now it is required that EX1 and EX2 have high priority and the others have low priority. Please use 51 single-chip microcomputer to implement it. You are required to draw the circuit diagram and compile the program (assuming that the interrupt sig
[Microcontroller]
51 MCU (32) - Serial communication example test
In "51 Single Chip Microcomputer (31) - Introduction to Serial Communication", we introduced the working principle and register definition of the 51 single chip microcomputer serial port. In this article, we will use an example to familiarize ourselves with the use of the 51 single chip microcomputer serial port. The
[Microcontroller]
51 MCU (32) - Serial communication example test
Design of Multi-channel Answering Machine Based on 51 Single-Chip Microcomputer
Colleges and universities are units with many departments and divisions, and there are many school activities. The activities of answering questions are exciting and interesting. There are few answering machines with more than 8 channels on the market, and they are expensive. A 4-channel answering machine costs at lea
[Microcontroller]
Design of Multi-channel Answering Machine Based on 51 Single-Chip Microcomputer
51 MCU pull-up resistor
1. In order to achieve quasi-3-state, the P0 port of 51 single-chip microcomputer adopts OC output, that is, collector floating output, also called totem pole output. This circuit structure has only pull-down capability, and there is no current in high-level output, which shows high-impedance state at high level; with
[Microcontroller]
Latest Microcontroller Articles
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号