In Line Assembly

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

In Line Assembly

跳至解决方案
1,369 次查看
uflchamp
Contributor I

I think I am missing something easy here. I made a function to wait a variable amount of time. My problem is that the D accumulator starts at zero after I tell it to load the ClockCycles variable. I believe the problem is that I need to do direct addressing. To do that I would perform LDD #ClockCycles, but Codewarrior doesn't accept that, and instead loads the address, which puts 0000 in the D accumulator.

 

The code is below:

 

// ---------------------------------------------
// VariableWaitAmount -- Pass in the amount of ns to delay, 40 ns min
// ---------------------------------------------  
void VarWait(long int nsToWait) {
 
  long int ClockCycles;
 
  ClockCycles = nsToWait / 40;
 
  asm START: LDD ClockCycles
  asm LOOP1: DBNE D, LOOP1
  return;
 
}

 

Thanks!

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
836 次查看
CompilerGuru
NXP Employee
NXP Employee

Can you show the disassembly?

 

Without having tried it out (no CW here), I would think your problem is the type long.

Long is a 4 byte type and a "LDD  ClockCycles" loads the two most significant bytes.

Try to make ClockCycles a unsigned long or use  LDD  ClockCycles:2 to read the 2 least significant bytes.

 

>I believe the problem is that I need to do direct addressing.

 

Direct addressing is for variables in the zero page. Accessing variables on the stack is done with IDX (or IDX1/IDX2) with the SP used as index register. I think the syntax LDD ClockCycles is fine, probably just reads the wrong part of the variable.

 

Daniel

 

在原帖中查看解决方案

0 项奖励
回复
1 回复
837 次查看
CompilerGuru
NXP Employee
NXP Employee

Can you show the disassembly?

 

Without having tried it out (no CW here), I would think your problem is the type long.

Long is a 4 byte type and a "LDD  ClockCycles" loads the two most significant bytes.

Try to make ClockCycles a unsigned long or use  LDD  ClockCycles:2 to read the 2 least significant bytes.

 

>I believe the problem is that I need to do direct addressing.

 

Direct addressing is for variables in the zero page. Accessing variables on the stack is done with IDX (or IDX1/IDX2) with the SP used as index register. I think the syntax LDD ClockCycles is fine, probably just reads the wrong part of the variable.

 

Daniel

 

0 项奖励
回复