Embedded Assembly code compiled wrong?

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

Embedded Assembly code compiled wrong?

3,152 次查看
UtopiaTim
Contributor III
Hi Folks,
 
I have embedded some assembly code in my C for the JM60
using CW 6.1.
 
What you see on the left is the source, and on the right
is the actual code that was generated in the 'assembly'
window.
 
How come the branch to location at 7900 isn't correct?
 
The code at 7900 should have the branch location as 78F4.
 
Thanks,
 
Tim
 
 
Key_temp = 0x00
Second_current = 0x01
 
 
Bottle_loop:
 asm{ 
  lda   Key_temp                   78F4  LDA  0x00B0
  cmp   #$00                       78F7  CMP  #0x00                       
  bne   check_keys                 78F9  BNE  *+14    ;abs = 0x7907
       
  lda   Second_current             78FB  LDA  0x0150           
  cmp   #$3b                       78FE  CMP  #0x3B            
  bne   Bottle_loop                7900  BNE  *+2     ;abs = 0x7902 <-- WRONG
                                                                  location, should 
                                                                     be 78F4
  jsr   update_clock               7902  JSR  0x79B6
  bra   Bottle_loop                7905  BRA  *+2     ;abs = 0x7907
       
check_keys:
    }

      
标签 (1)
标记 (1)
0 项奖励
回复
6 回复数

1,537 次查看
bigmac
Specialist III
Hello,
 
I suspect the problem may be because the label Bottle_loop has been defined at a location outside the assembly block.
 
When I attempted to compile the code, using an earlier version of CW, I received the error "Label not set", and the compile failed.  Once the label was positioned within the block, the intended result was obtained.
 
Regards,
Mac
 
 
 
0 项奖励
回复

1,537 次查看
UtopiaTim
Contributor III
Thanks Mac,
 
I didn't get any warning or error messages, but I'll give it a try.
 
Again,
 
Thanks!
 
TIm
0 项奖励
回复

1,537 次查看
CompilerGuru
NXP Employee
NXP Employee
I think Bigmag did notice the issue, well I did not see it.
Is
Bottle_loop not defined in a asm section?
Basically labels outside of asm sections are plain C labels to be used with the C goto statement. Labels inside of asm sections are HLI labels, and the two namespaces are distinct, they do not mix.

Daniel
0 项奖励
回复

1,537 次查看
bigmac
Specialist III
Hello,


CompilerGuru wrote:
I think Bigmag did notice the issue, well I did not see it.
Is
Bottle_loop not defined in a asm section?
Basically labels outside of asm sections are plain C labels to be used with the C goto statement. Labels inside of asm sections are HLI labels, and the two namespaces are distinct, they do not mix.

Daniel


To clarify my findings, I needed to alter the label position as follows, to avoid the compile error.  This seems to tally with Daniel's post.
 
  asm { 
Bottle_loop:
   lda   Key_temp
    cmp   #$00                       
    bne   check_keys
       
    lda   Second_current
    cmp   #$3b 
    bne   Bottle_loop 
 
    jsr   update_clock 
    bra   Bottle_loop
check_keys:
    }


The main issue seems to be why the original code correctly generated an error with CW5.0, but did not with CW6.1.  The erroneous result was to ignore the branch, and skip to the next instruction, for both instances within the original code.
 
Regards,
Mac
 
0 项奖励
回复

1,537 次查看
CompilerGuru
NXP Employee
NXP Employee
Is there another global symbol (function, variable) named Bottle_loop?
That would explain the generated code.
0 项奖励
回复

1,537 次查看
CrasyCat
Specialist III
Hello
 
I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
 
CrasyCat
0 项奖励
回复