Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

syntax for asm in sdcc

225 views
Skip to first unread message

john111w

unread,
Jun 8, 2012, 11:27:25 AM6/8/12
to
I need to use the sdcc compiler in an IDE. I have about 16K of ASM51 code
that I need to compile with sdcc so that I can use the source in the debug
pane. The IDE only shows dissambly (with label numbers) unless you use C.

So I fugured I'd create a C "shell" and import my asm51 file

Where can I go to learn how to embed the asm?

The IDE has a C example which compiles with sdcc. I tried 2 hours of web
searches last night to find the syntax to add 2 trial lines.

__asm
mov a,b
mov b,a
__ endasm

I tried single underscore, double underscore, quotes, slashes, parens, as
shown in many web search examples
I even tried without the mov's just
__asm/
__endasm as shown in an SDCC forum example.

I can't see how to create a thread in the SourceForge.net to ask this
question
Help is greatly appreciated.


---------------------------------------
Posted through http://www.EmbeddedRelated.com

john111w

unread,
Jun 8, 2012, 11:50:18 AM6/8/12
to

Rocky

unread,
Jun 8, 2012, 12:15:27 PM6/8/12
to
Mmmm, I'm not sure about the '/' after asm. This is what I used a
while ago to do some footling with interupts.


__asm
push psw
push acc
push dpl
push dph
push b
mov a,#(.+9)
push acc
mov a,#((.+5) >> 8)
push acc
reti

nop

__endasm;

Rich Webb

unread,
Jun 8, 2012, 12:04:46 PM6/8/12
to
I still have a project that's still using sdcc, although it's an older
rev (2.6) and I haven't been following possible syntax shifts in later
releases. That said, it looks like you need
_asm
<stuff>
_endasm;
as in this example from the 2.6 manual:

void to_buffer( unsigned char c )
{
c; // to avoid warning: unreferenced function argument
_asm
; save used registers here.
; If we were still using r2,r3 we would have to push them here.
; if( head != (unsigned char)(tail-1) )
mov a,_tail
dec a
xrl a,_head
; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
jz t_b_end$
;
; buf[ head++ ] = c;
mov a,dpl ; dpl holds lower byte of function argument
mov dpl,_head ; buf is 0x100 byte aligned so head can be used directly
mov dph,#(_buf> >8)
movx @dptr,a
inc _head
; we could do an ANL _head,#0x0f here to use a smaller buffer (see
above)
t_b_end$:
; restore used registers here
_endasm;
}

--
Rich Webb Norfolk, VA

john111w

unread,
Jun 8, 2012, 12:24:44 PM6/8/12
to
>On Jun 8, 5:50=A0pm, "john111w" <greenwick@n_o_s_p_a_m.nni.com> wrote:
>> I need to use the sdcc compiler in an IDE. I have about 16K of ASM51
code
>> that I need to compile with sdcc so that I can use the source in the
debu=
>g
>> pane. The IDE only shows dissambly (with label numbers) unless you use
C.
>>
>> So I fugured I'd create a C "shell" and import my asm51 file
>>
>> Where can I go to learn how to embed the asm?
>>
>> The IDE has a C example which compiles with sdcc. I tried 2 hours of
web
>> searches last night to find the syntax to add 2 trial lines.
>>
>> __asm
>> mov a,b
>> mov b,a
>> __ endasm
>>
>> I tried single underscore, double underscore, quotes, slashes, parens,
as
>> shown in many web search examples
>> I even tried without the mov's just
>> __asm/
>> __endasm =A0 as shown in an SDCC forum example.
>>
>> I can't see how to create a thread in the SourceForge.net to ask this
>> question
>> Help is greatly appreciated.
>>
>> ---------------------------------------
>> Posted throughhttp://www.EmbeddedRelated.com
>
>Mmmm, I'm not sure about the '/' after asm. This is what I used a
>while ago to do some footling with interupts.
>
>
> __asm
> push psw
> push acc
> push dpl
> push dph
> push b
> mov a,#(.+9)
> push acc
> mov a,#((.+5) >> 8)
> push acc
> reti
>
> nop
>
> __endasm;
>

john111w

unread,
Jun 8, 2012, 12:27:58 PM6/8/12
to
>On Jun 8, 5:50=A0pm, "john111w" <greenwick@n_o_s_p_a_m.nni.com> wrote:
>> I need to use the sdcc compiler in an IDE. I have about 16K of ASM51
code
>> that I need to compile with sdcc so that I can use the source in the
debu=
>g
>> pane. The IDE only shows dissambly (with label numbers) unless you use
C.
>>
>> So I fugured I'd create a C "shell" and import my asm51 file
>>
>> Where can I go to learn how to embed the asm?
>>
>> The IDE has a C example which compiles with sdcc. I tried 2 hours of
web
>> searches last night to find the syntax to add 2 trial lines.
>>
>> __asm
>> mov a,b
>> mov b,a
>> __ endasm
>>
>> I tried single underscore, double underscore, quotes, slashes, parens,
as
>> shown in many web search examples
>> I even tried without the mov's just
>> __asm/
>> __endasm =A0 as shown in an SDCC forum example.
>>
>> I can't see how to create a thread in the SourceForge.net to ask this
>> question
>> Help is greatly appreciated.
>>
>> ---------------------------------------
>> Posted throughhttp://www.EmbeddedRelated.com
>
>Mmmm, I'm not sure about the '/' after asm. This is what I used a
>while ago to do some footling with interupts.
>
>
> __asm
> push psw
> push acc
> push dpl
> push dph
> push b
> mov a,#(.+9)
> push acc
> mov a,#((.+5) >> 8)
> push acc
> reti
>
> nop
>
> __endasm;
>
I just tried:
__asm
__endasm; received syntax error token-> '__endasm' column 8 (the letter
m)

Tim Wescott

unread,
Jun 8, 2012, 1:23:17 PM6/8/12
to
Perhaps you need to indent? You shouldn't -- but the compiler is
obviously being picky on you.

(I really like the Gnu "asm" syntax by the way -- in my opinion it's the
best thought-out, and complete, way to implement assembly that I've seen).

As a work-around, can you implement those critical functions entirely in
assembly? You'll have call overhead, but you'll have less totally non-
portable structures scattered around your code.

--
My liberal friends think I'm a conservative kook.
My conservative friends think I'm a liberal kook.
Why am I not happy that they have found common ground?

Tim Wescott, Communications, Control, Circuits & Software
http://www.wescottdesign.com

Rocky

unread,
Jun 8, 2012, 5:02:12 PM6/8/12
to
> Posted throughhttp://www.EmbeddedRelated.com- Hide quoted text -
>
> - Show quoted text -

I tried downloading the latest version and the code compiled - didn't
check if it worked :( too much hassle right now.
Version:
C:\SDCC\bin>sdcc -v
SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/
ds400/hc08/s08
3.1.5 #7874 (Jun 7 2012) (MINGW32)

C:\SDCC\bin>

Philipp Klaus Krause

unread,
Jun 11, 2012, 3:28:05 AM6/11/12
to
On 08.06.2012 23:02, Rocky wrote:

> I tried downloading the latest version and the code compiled - didn't
> check if it worked :( too much hassle right now.
> Version:
> C:\SDCC\bin>sdcc -v
> SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/
> ds400/hc08/s08
> 3.1.5 #7874 (Jun 7 2012) (MINGW32)

Historically sdcc used _asm and _endasm. Some time ago this was changed
to also allow __asm and __endasm. Recently the old _asm and _endasm has
been removed, and sdcc now only supports the standard-compliant __asm
and __endasm. So depending on how old the sdcc version used is, it will
support _asm, __asm or both.

Philipp
0 new messages