⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cc65-8.html

📁 cc65 的编译器文档
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML><HEAD> <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.20"> <TITLE>cc65 Users Guide: Register variables</TITLE> <LINK HREF="cc65-9.html" REL=next> <LINK HREF="cc65-7.html" REL=previous> <LINK HREF="cc65.html#toc8" REL=contents></HEAD><BODY><A HREF="cc65-9.html">Next</A><A HREF="cc65-7.html">Previous</A><A HREF="cc65.html#toc8">Contents</A><HR><H2><A NAME="regvars"></A> <A NAME="s8">8.</A> <A HREF="cc65.html#toc8">Register variables</A></H2><P>The runtime for all supported platforms has 6 bytes of zero page spaceavailable for register variables (this could be increased, but I think it's agood value). So you can declare register variables up to a total size of 6 perfunction. The compiler will allocate register space on a "first come, firstserved" base and convert any <CODE>register</CODE> declarations that exceed theavailable register space silently to <CODE>auto</CODE>. Parameters can also bedeclared as <CODE>register</CODE>, this will in fact give slightly shorter code thanusing a register variable.</P><P>Since a function must save the current values of the registers on entry andrestore them on exit, there is an overhead associated with register variables,and this overhead is quite high (about 20 bytes per variable). This means thatjust declaring anything as <CODE>register</CODE> is not a good idea.</P><P>The best use for register variables are pointers, especially those that pointto structures. The magic number here is about 3 uses of a struct field: If thefunction contains this number or even more, the generated code will be usuallyshorter and faster when using a register variable for the struct pointer. Thereason for this is that the register variable can in many cases be used as apointer directly. Having a pointer in an auto variable means that this pointermust first be copied into a zero page location, before it can be dereferenced.</P><P>Second best use for register variables are counters. However, there is notmuch difference in the code generated for counters, so you will need at least100 operations on this variable (for example in a loop) to make it worth thetrouble. The only savings you get here are by the use of a zero page variableinstead of one on the stack or in the data segment.</P><P>Register variables must be explicitly enabled by using <CODE>-Or</CODE> or <CODE>-r</CODE> onthe command line. Register variables are only accepted on function top level,register variables declared in interior blocks are silently converted to<CODE>auto</CODE>. With register variables disabled, all variables declared as<CODE>register</CODE> are actually auto variables.</P><P>Please take care when using register variables: While they are helpful and canlead to a tremendous speedup when used correctly, improper usage will causebloated code and a slowdown.</P><HR><A HREF="cc65-9.html">Next</A><A HREF="cc65-7.html">Previous</A><A HREF="cc65.html#toc8">Contents</A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -