Hi,

Brandon Fosdick schrieb:
> sdcc is generating an awful lot of instructions just to set some pins.

Strictly speaking Keil uses 4 instructions
whereas SDCC uses only 3 instructions for:

  P0DIR = 0x0;
  while(1)
    P0 = 0xFF;

Both compilers use 8 bytes of code memory and the
same number of cycles on a plain 8051 though.
The difference is in the startup code that is being linked.

Keil uses a clever scheme there.
SDCC links code that is not customized for your application
and uses generic code which f.e. includes code for an
external startup routine.

But you have (manual) control over this code (see Manual 3.12.1)
and if you f.e. link an adapted crtstart.asm
(empty section GSINIT2 so only setting the stackpinter is set)
then you'll have shaved off 14 bytes:)

  sdcc --no-xinit-opt --main-return --iram-size 0x80 crtstart.rel t.c

you arrive at:

:020000040000FA
:1A000000020006020012758107E4787FF6D8FD0200037593007580FF80FBAB
:00000001FF

which (passed through d52 disassembler with "d52 -pngd t.ihx") is:

        ljmp    X0006           ; 0000   02 00 06   ...
;
X0003:  ljmp    X0012           ; 0003   02 00 12   ...
;
X0006:  mov     sp,#0x7         ; 0006   75 81 07   u..
        clr     a               ; 0009   e4         d
        mov     r0,#0x7f        ; 000a   78 7f      x.
X000c:  mov     @r0,a           ; 000c   f6         v
        djnz    r0,X000c        ; 000d   d8 fd      X}
        ljmp    X0003           ; 000f   02 00 03   ...
;
X0012:  mov     93h,#0x0        ; 0012   75 93 00   u..
X0015:  mov     p0,#0xff        ; 0015   75 80 ff   u..
        sjmp    X0015           ; 0018   80 fb      .{

You could strip that down yet another 4-5 bytes using ajmp
and removing one ljmp.

Considering it's about 5 years ago from Erik Petrich's commit
2004-03-17 for the initialization code it's strange that
noone yet (seems to have) posted a minimized crtstart.asm :^)




> Keil is putting the bulk of the code at 0x800 with a jmp at 0x0, but I 
> don't see any reason it has to be that way.

It's because Keil's evaluation version is code size
limited to 2k(**) (for other limitations see Keil's website).
For target devices with 2k code memory (0x800 bytes)
this limitation would not have an effect so Keil locates
the bulk of the code to above 0x800.

>                                             Nor do I see a way to get
> sdcc to do the same thing.

See option --code-loc if you need to do the same thing
with SDCC.




Also use D51 (Manual 6.4) to disassemble both Intel Hex Files.
You'll note a difference that can be changed with option --iram-size.
And a different SFR address is used for port initialisation.

Greetings,
Frieder




(**) Keil evaluation versions which allow for 4k code are
shipped with some low cost 8051 development kits.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to