axiya 发表于 2006-12-20 09:14:34

马老师!!!!!!!请赐教下一个 mega128嵌入汇编的问题,望指教啊!!!!

马老师,我现在要编写个PWM发射数据的程序。

主程序用C编写,现在以知要 发那些数据,我先把这些数据放一个数组里面,

然后编写一个发射这些数据的汇编程序,并嵌入C语言主程序中

汇编嵌入C语言中我会,但我问题就是不知道怎么在汇编程序找到C语言主程序的数组并发送他们?

就是怎么去找着个数组的位置??怎么编写??

望各位老师赐教,本人刚开始学Mega128,用的软件是ICC和AVR studio

machao 发表于 2007-3-9 23:37:37

External Names

External C names are prefixed with an underscore, e.g. the function main is _main if referenced in an assembly module. Names are significant to 32 characters. To make an assembly object global, use two colons after the name. For example,



_foo::



.word 1



(In the C file)



extern int foo;



Argument and Return Registers



The first argument is passed in registers R16/R17 if it is an integer and R16/R17/R18/R19 if it is a long or floating point. The second argument is passed in R18/R19 if available. All other remaining arguments are passed on the software stack.



Integer arguments smaller than ints (i.e. char) are not extended to in IF the function prototype is available. If registers are used to pass byte arguments, it will use both registers but the higher register is undefined. For example, if the first argument is a byte, both R16/R17 will be used with R17 being undefined. Byte arguments passed on the software stack take up only a single byte. In the future release, byte arguments passed in registers will be packed tightly.



If R16/R17 is used to pass the first argument and the second argument is a long or float, the lower half of the second argument is passed in R18/R19 and the upper half is passed on the software stack.



Integer values are returned in R16/R17 and longs and floats are returned in R16/R17/R18/R19. Byte values are returned in R16 with R17 undefined.



Preserved Registers



An assembly function must save and restore the following registers:



R28/R29 or Y, this is the frame pointer.

        R10/R11/R12/R13/R14/R15/R20/R21/R22/R23



These registers are called preserved registers since their contents are unchanged by a function call. You can ask the compiler not to use the registers R20, R21, R22, and R23, then you do not need to save and restore these 4 registers.



Volatile Registers



The other registers:



R0/R1/R2/R3/R4/R5/R6/R7/R8/R9/R24/R25/R26/R27/R30/R31

        SREG



can be used in a function without being saved or restored. These registers are called volatile registers since their contents may be changed by a function call.



Interrupt Handlers



以上摘自ICC的HELP,你参考一下。



建议C调用汇编子程序时,将数组的头指针作为参数传到子程序,在汇编中从相应的寄存器中得到头指针。
页: [1]
查看完整版本: 马老师!!!!!!!请赐教下一个 mega128嵌入汇编的问题,望指教啊!!!!