This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
问题描述: delay_us(a),long a=10 比 delay_us(10)用定时器实测前者为15us,后者为10us 28377s,delay_us也已经定义到RAM里了,测试方法:程序在线调试通过一个定时器在CCS窗口中看的,又试了delay_us(a),long a=20 比 delay_us(20)也是多5us. a定义成int long float 都试了,都是这个现象。 delay_us是汇编写的,
请问为什么会有这样的现象?还是说汇编写的代码不可以这样用一个变量作为参数,只能写成 10 20之类的数字?
求解。
;// The C assembly call from the DELAY_US(time) macro will ;// look as follows: ;// extern void Delay(long LoopCount); ;// MOV AL,#LowLoopCount ;// MOV AH,#HighLoopCount ;// LCR _Delay ;// Or as follows (if count is less then 16-bits): ;// MOV ACC,#LoopCount ;// LCR _Delay
;There is a 9/10 cycle overhead and each loop
;takes five cycles. The LoopCount is given by
;the following formula:
; DELAY_CPU_CYCLES = 9 + 5*LoopCount
; LoopCount = (DELAY_CPU_CYCLES - 9) / 5
; The macro DELAY_US(A) performs this calculation for you
您可以对照一下下图的反汇编