6502 MCU Programming--Pseudo Instruction 2

Publisher:RadiantGazeLatest update time:2015-12-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
** Macro Instructions ** What makes me extremely excited is that 6502_Macroassembler & Simulator has powerful macro functions . This undoubtedly makes program writing much simpler and more convenient . Let's talk about the format of macros first . Macro name : .MACRO  macro virtual parameter 1, macro virtual parameter 2, macro virtual parameter 3..... macro body.ENDM Here , .MACRO and .ENDM must appear in pairs . The format of macro calls : macro name macro actual parameter 1, macro actual parameter 2, macro parameter 3 When the source program with macro calls is compiled , each macro call will be expanded by the compiler . Macro expansion is actually the macro body designed during macro definition to replace the corresponding macro instruction name , and the actual parameters are used to replace the virtual parameters to form actual code that meets the function and can be executed. Let's give an example : Implement the interrupt instruction INT. As we all know , the current 6502 compiler does not support the INT instruction , which causes inconvenience to writing , but now we can use macros to implement it . ORG $0000 INT: .MACRO INT_PARAM .DB $00 .DW INT_PARAM .ENDM indicates that INT is the macro name . Note that it should be followed by : , INT_PARAM is a virtual parameter . Since the machine code of INT is 00, we .DB $00 in the macro body . For example , INT $C008 has a machine code of 00 08 C0, so we .DW INT_PARAM. In this way , we implement the INT instruction . For example, if we input INT $C008 in the program , it has the same function as INT $C008 in Wenquxing . Let me give you another example . In 6502 , there is no instruction to directly push or pop the stack with register X. Here we use macros to implement it . ORG $0000 PHX: .MACRO TXA PHA .ENDM PLX: .MACRO PLA TAX .ENDM MAIN: PHX ... PLX RTS See , we can use PHX and PLX in the program . Although macros have a lot of functions , we cannot use them indiscriminately , because macros are different from subroutines . Subroutines are called by JSR and returned by RTS , so the machine code of the subroutine after assembly only occupies one program segment , no matter how many times it is called , which saves memory . Each time a macro instruction is called , it occupies a program segment. The more times it is called , the more memory is occupied . Therefore, in terms of overhead , subroutines are better than macro instructions . However, from the perspective of program execution time , each time a subroutine is called, the return address must be protected and restored , which takes some time. Macro instruction calls do not require this process .
   

   

     
    







   

   
   
   
   
    
   

    
    
   

    
    
   

    
    
    

   The execution time is shorter , so from the execution time point of view , macro instructions are better than subroutines . Therefore , when a program segment that needs to be accessed multiple times is long and the number of accesses is not too many , it is better to use a subroutine ; when a program segment that needs to be accessed multiple times is short and the number of accesses is very frequent , it is better to use a macro instruction .
   
Reference address:6502 MCU Programming--Pseudo Instruction 2

Previous article:8-bit microcontroller division function
Next article:6502 MCU Programming--Pseudo Instruction 1

Recommended ReadingLatest update time:2024-11-16 20:50

6502 MCU Programming--Pseudo Instruction 1
**Byte definition pseudo instruction.DB** This pseudo instruction can define data, such as bytes, strings, Chinese characters, etc. 1. Define bytes Add $ before the byte, it means hexadecimal Add @ before the byte, it means binary Add nothing before the byte, it means decimal For example.ORG $0000 .DB $30, $31,
[Microcontroller]
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号