Problems combining SDCC and ASM code compiling on the Intel 8051

3.6k views Asked by At

We are trying to compile our C code which includes a lot of assembly for various operations (timing, producing output waveforms, and measuring input frequency).

We keep getting the same error for a few of our ASM operations:

".org in REL area or directive / mnemonic error"

In our code below, we get 3 errors (i commented on which lines they happen, and what exactly the error we get is. Thanks!

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
}
1

There are 1 answers

1
Matthew Slattery On BEST ANSWER

sdcc's assembler doesn't support the H and B suffix syntax for immediate values that you're using.

Try #0xF0 instead of #0F0H, and #0b00000101 instead of #00000101B, etc.