简体   繁体   English

MPLAB / XC8无法跳转到ASM?

[英]MPLAB/XC8 can't jump in ASM?

I have a project for the PIC18F25K50 of mixed C and Assembly; 我有一个PIC18F25K50混合C和装配项目; most of what I want to do I can easily manage (and must for efficiency) in Assembly, but some parts where I care more about ease of development use C. I actually have a couple of these, and I keep encountering the same issue: I can't use ASM to jump to a label. 我想做的大部分工作都可以在Assembly中轻松管理(并且必须提高效率),但有些部分我更关心开发的易用性。我实际上有几个这样的部分,我一直遇到同样的问题:我无法使用ASM跳转到标签。 Every single function to jump - CALL , GOTO , BNC , and so on - will fail if given a label, setting PC to some random-but-consistent value where there are no instructions, causing the program to hang. 跳转的每个函数 - CALLGOTOBNC等 - 如果给出标签,将失败,将PC设置为某些随机但一致的值,其中没有指令,导致程序挂起。 Using an address works fine: BC $+4 skips the next line. 使用地址工作正常: BC $+4跳过下一行。

An example of what does not work is this: 不起作用的一个例子是:

#asm
_waitUS:
    GLOBAL  _waitUS
waitLoop:
    //12 cycles = 1 microsecond:
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    DECFSZ  WREG, F, ACCESS
    GOTO waitLoop
    RETURN
#endasm

void main() {
    //DEBUG:
    waitUS(6);
}

Now, this may not work overall, and I am begging you to focus on the issue of jumping - this is still in prototyping because I can't even get the function called. 现在,这可能不会全局起作用,我恳求你专注于跳跃问题 - 这仍然是原型设计,因为我甚至无法获得调用的函数。 The program does compile without issue. 该程序确实编译没有问题。

As soon as waitUS(6) is called, the PC jumps from - in my case - 0x7C96 to 0x52 . 一旦waitUS(6) ,PC就会从 - 在我的情况下 - 0x7C960x52 Swapping the C call out for MOVLW 6; CALL _waitUS 将C呼叫MOVLW 6; CALL _waitUS MOVLW 6; CALL _waitUS breaks in exactly the same way. MOVLW 6; CALL _waitUS以完全相同的方式中断。

If I strictly use C for calling/jumping (as I had to in the previous project), it works fine, and figures out where it's going. 如果我严格使用C进行呼叫/跳转(正如我在之前的项目中所做的那样),它运行正常,并找出它的去向。

I've been searching for an answer to this for a few weeks now, and still haven't seen anyone else with this problem, even though every project I make (including plaintext in notepad, compiling via command line) has the exact same issue. 我几个星期以来一直在寻找这个问题的答案,并且仍然没有看到其他人遇到这个问题,即使我做的每个项目(包括记事本中的明文,通过命令行编译)都有完全相同的问题。 What the heck is up with this? 这到底是怎么回事?

Edit: Having discovered the program memory view, I was able to get a better idea of what it's doing. 编辑:发现程序内存视图后,我能够更好地了解它正在做什么。 The compiler does know where the functions are, and it is trying to jump to the right location. 编译器知道的功能是,它试图跳转到正确的位置。 Apparently, CALL just doesn't know where it's going. 显然,CALL只是不知道它的发展方向。

Example: Address 0x7C92 contains CALL 0x2044, 0 . 示例:地址0x7C92包含CALL 0x2044, 0 That is precisely what it ought to, that is where the desired function starts. 这恰恰是应该的,也就是期望的功能开始的地方。 However, upon running this instruction, PC is altered to 0x205E , missing half of the function. 但是,在运行此指令时, PC被更改为0x205E ,缺少一半的功能。

Attempting to be clever, I decided to tack on several NOPs to the start of the function after its label, lining the real code up with 0x205E . 试图变得聪明,我决定在标签之后将几个NOP添加到函数的开头,用0x205E实际代码。 Unfortunately, it seems any change alters where its unpredictable jumping will land, and it then landed at 0x2086 instead. 不幸的是,似乎任何变化都会改变其不可预测的跳跃将会降落的地方,然后它会降落到0x2086

Incidentally, when it starts running at random places, it will often run across a GOTO - and it will jump to the specified location as intended. 顺便提一下,当它开始在随机位置运行时,它经常会在GOTO运行 - 它按预期跳转到指定的位置。 This only works within the same function, as trying to use GOTO instead of CALL ends up in the same incorrect location, despite what the compiled result demands. 这只适用于同一个函数,因为尽管编译结果需要,但尝试使用GOTO而不是CALL最终会在同一个错误的位置。

the .pdf document at: 
<http://ww1.microchip.com/downloads/en/DeviceDoc/33014K.pdf>

has many examples on how to code the PIC18. 
Here is one such example:

RST CODE 0x0 ;The code section named RST
    ;is placed at program memory
    ;location 0x0. The next two
    ;instructions are placed in
    ;code section RST.
    pagesel start ;Jumps to the location labelled
    goto start ;’start’.

PGM CODE ;This is the beginning of the
    ;code section named PGM. It is
    ;a relocatable code section
    ;since no absolute address is
    ;given along with directive CODE.
start
    movlw D'10'
    movwf delay_value
    xorlw 0x80
    call delay
    goto start
    end 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM