Automatically Initializing Data Segment Values in MAX-IDE
[09-11 23:02:11] 来源:http://www.88dzw.com 单片机学习 阅读:8704次
文章摘要:In applications written in C or another high-level language and compiled into assembly code, the compiler typically handles the allocation of space for variables (as well as the process of initializing variables to predefined starting values) automatically. In this case, the user only needs to decla
Automatically Initializing Data Segment Values in MAX-IDE,标签:单片机开发,单片机原理,单片机教程,http://www.88dzw.comIn applications written in C or another high-level language and compiled into assembly code, the compiler typically handles the allocation of space for variables (as well as the process of initializing variables to predefined starting values) automatically. In this case, the user only needs to declare the variable, its type, and (optionally) its initial value. The compiler handles the rest.
unsigned int c = 0x1234;However, when writing applications directly in MAXQ assembly language, the allocation of space for variables and setting the variables to initial values must be performed explicitly. This detailed action allows tighter control of the resources available on the MAXQ microcontroller, but adds some complexity to the system.
For small assembly-based applications or those which do not require a large amount of working space, internal registers can be used to store all application variables. This approach provides two important advantages:
- Compact, fast code. Register variables can be read from, written to, or copied to another register variable in as little as one instruction cycle, depending on the location of the register. On MAXQ20-based microcontrollers, no more than two instruction cycles will generally be required in the worst case.
- Direct operations on variables. Some internal register locations can be operated on directly. For example, any of the 16 working accumulators, A[0] through A[15], can be selected (using the AP register) as the active accumulator, Acc. This means that if an operation needs to be performed on a variable stored in one of these registers, it can be performed directly on that register without having to copy the value out, perform the operation, and copy the value back in. Similarly, variables stored in the LC[0] and LC[1] registers can be used directly as loop counters by executing the djnz instruction.
move DP[0], #0010h ; Location of variable in data memory move Acc, @DP[0] ; Read variable add #1 ; Increment variable value by 1 move @DP[0], Acc ; Store variable back in data memoryIf a long series of calculations must be performed on a variable, the value of that variable can be copied into a working register, as shown in the example code above. All intermediate operations can be performed using that working register, and the value can be copied back out to the variable once calculations are complete.
Segment Declarations in MAX-IDE
Once the decision is made to store application variables in SRAM-based data memory, how do you determine where to store the variables?Typically, all of the data memory is available for application use, except for the highest 32 bytes in memory which are used by the debugger. This means that declaring a variable is simply a matter of defining a location for it in data memory. This location is then used by code whenever the variable is read or written. The #define macro can be used to associate a variable location with a symbolic name.
#define VarA #0020h #define VarB #0021h #define VarC #0022h move DP[0], VarA ; Point to VarA variable move Acc, @DP[0] ; Read value of variable move DP[0], VarB ; Point to VarB variable move @DP[0], Acc ; Copy VarA to VarB move DP[0], VarC ; Point to VarC variable move @DP[0], #1234h ; Set VarC = 1234h
Tag:单片机学习,单片机开发,单片机原理,单片机教程,单片机学习
《Automatically Initializing Data Segment Values in MAX-IDE》相关文章
- › 自动测试设备的预算-Automatic Test Equip
- › 自动重试控制器套装电信应用-Auto-Retry Contr
- › Automatic Test Equipment on a
- › Automatically Initializing Data Segment Values in MAX-IDE
- › 基于AutoCAD的线切割加工CAD/CAM技术
- 在百度中搜索相关文章:Automatically Initializing Data Segment Values in MAX-IDE
- 在谷歌中搜索相关文章:Automatically Initializing Data Segment Values in MAX-IDE
- 在soso中搜索相关文章:Automatically Initializing Data Segment Values in MAX-IDE
- 在搜狗中搜索相关文章:Automatically Initializing Data Segment Values in MAX-IDE
分类导航
最新更新