In Line Assembly

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
1,372件の閲覧回数
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 解決策
839件の閲覧回数
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 返信
840件の閲覧回数
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 件の賞賛
返信