【问题标题】:Problems combining SDCC and ASM code compiling on the Intel 8051在 Intel 8051 上结合 SDCC 和 ASM 代码编译的问题
【发布时间】:2011-06-27 19:05:51
【问题描述】:

我们正在尝试编译我们的 C 代码,其中包括用于各种操作(定时、产生输出波形和测量输入频率)的大量程序集。

我们的一些 ASM 操作不断收到相同的错误:

“REL 区域中的.org 或指令/助记符错误”

在下面的代码中,我们得到了 3 个错误(我评论了它们发生的行,以及我们得到的错误究竟是什么。谢谢!

void getFrequency(int *freqHi, int *freqLo) 
{
    __asm
    ;
    ; A program that measures the frequency at pin T0 (P1.2)

    ljmp GetFreq

    Wait1s:
        mov R2, #40
    M3: mov R1, #250
    M2: mov R0, #181
    M1: djnz R0, M1 ; 2 machine cycles-> 2*0.27126us*181=100us
        djnz R1, M2 ; 100us*250=0.025s
        djnz R2, M3 ; 0.025s*40=1s
        ret

    ;Initializes timer/counter 0 as a 16-bit counter
    InitTimer0:
        setb T0 ; Enable pin T0 as input
        clr TR0 ; Stop timer 0
        mov a,#0F0H ; ERROR <o> .org in REL area or directive / mnemonic error
        anl a,TMOD
        orl a,#00000101B ; Set timer 0 as 16-bit counter ERROR <o> .org in REL area or directive / mnemonic error
        mov TMOD,a
        ret

    GetFreq:
        mov SP, #7FH ; Set the stack pointer to the begining of idata ERROR <o> .org in REL area or directive / mnemonic error

        lcall InitTimer0

        clr TR0 ; Stop counter 0
        mov TL0, #0
        mov TH0, #0

        setb TR0 ; Start counting
        lcall Wait1s ; Wait one second
        clr TR0 ; Stop counter 0, TH0-TL0 has the frequency

        mov R0, TH0
        mov R1, TL0

        mov _freqHi, R0
        mov _freqLo, R1

    __endasm;

    // freqHi, freqLo have respective values
}

【问题讨论】:

  • 看来您的 mov 语法错误。 在发布之前阅读您的错误消息
  • 嗯,我们确实阅读了这条消息。我想问题是这段代码之前在汇编中独立编译时运行良好,但现在我们将它与 C 集成我们遇到了问题。

标签: assembly 8051 sdcc


【解决方案1】:

sdcc 的汇编程序不支持您正在使用的立即数的 HB 后缀语法。

尝试用#0xF0 代替#0F0H,用#0b00000101 代替#00000101B,等等。

【讨论】:

  • 感谢您的回答!!最后我们只是用 C 重写了代码,但这对其他人会有所帮助。
猜你喜欢
  • 2014-11-04
  • 2020-09-29
  • 2018-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多