Share

Small Device C Compiler

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

newb question

You are viewing a single message from this topic. View all messages.

  1. 2007-01-15 17:40:15 UTC
    Hello,
    At this point i do not have real 8051, so i try to use sdcdb
    Linux environment (Ubuntu)
    xdesk:~/megab/8051$ sdcc -v
    SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.6.0 #4309 (Sep 28 2006) (UNIX)

    this is the code (single C file)


    static unsigned char idleTask(unsigned char context)
    {
    context++;
    return context;
    }

    static void mainLoop()
    {
    unsigned char context = 0;
    while (1)
    {
    context = idleTask(context);
    }
    }

    void main()
    {
    mainLoop();
    }


    This is how i compile it
    sdcc --model-small --debug test_00.c (see assembler below)

    I run debugger
    sdcdb test_00
    and get
    (sdcdb) run
    Starting program
    Stack underflow
    (sdcdb)
    I tried to add a breakpoint to the idleTask. idleTask() is called 3 times and after that i get "Stack underflow"

    May you help me with this one ?
    I read the SDCC manual. I will appreciate any additional links to 8051 tutorials/beginners guides.

    Thank you


    ;--------------------------------------------------------
    ; File Created by SDCC : FreeWare ANSI-C Compiler
    ; Version 2.6.0 #4309 (Sep 28 2006)
    ; This file generated Mon Jan 15 19:34:02 2007
    ;--------------------------------------------------------
    .module test_00
    .optsdcc -mmcs51 --model-small

    ;--------------------------------------------------------
    ; Public variables in this module
    ;--------------------------------------------------------
    .globl _main
    ;--------------------------------------------------------
    ; special function registers
    ;--------------------------------------------------------
    .area RSEG (DATA)
    ;--------------------------------------------------------
    ; special function bits
    ;--------------------------------------------------------
    .area RSEG (DATA)
    ;--------------------------------------------------------
    ; overlayable register banks
    ;--------------------------------------------------------
    .area REG_BANK_0 (REL,OVR,DATA)
    .ds 8
    ;--------------------------------------------------------
    ; internal ram data
    ;--------------------------------------------------------
    .area DSEG (DATA)
    ;--------------------------------------------------------
    ; overlayable items in internal ram
    ;--------------------------------------------------------
    .area OSEG (OVR,DATA)
    ;--------------------------------------------------------
    ; Stack segment in internal ram
    ;--------------------------------------------------------
    .area SSEG (DATA)
    __start__stack:
    .ds 1

    ;--------------------------------------------------------
    ; indirectly addressable internal ram data
    ;--------------------------------------------------------
    .area ISEG (DATA)
    ;--------------------------------------------------------
    ; bit data
    ;--------------------------------------------------------
    .area BSEG (BIT)
    ;--------------------------------------------------------
    ; paged external ram data
    ;--------------------------------------------------------
    .area PSEG (PAG,XDATA)
    ;--------------------------------------------------------
    ; external ram data
    ;--------------------------------------------------------
    .area XSEG (XDATA)
    ;--------------------------------------------------------
    ; external initialized ram data
    ;--------------------------------------------------------
    .area XISEG (XDATA)
    .area HOME (CODE)
    .area GSINIT0 (CODE)
    .area GSINIT1 (CODE)
    .area GSINIT2 (CODE)
    .area GSINIT3 (CODE)
    .area GSINIT4 (CODE)
    .area GSINIT5 (CODE)
    .area GSINIT (CODE)
    .area GSFINAL (CODE)
    .area CSEG (CODE)
    ;--------------------------------------------------------
    ; interrupt vector
    ;--------------------------------------------------------
    .area HOME (CODE)
    __interrupt_vect:
    ljmp __sdcc_gsinit_startup
    ;--------------------------------------------------------
    ; global & static initialisations
    ;--------------------------------------------------------
    .area HOME (CODE)
    .area GSINIT (CODE)
    .area GSFINAL (CODE)
    .area GSINIT (CODE)
    .globl __sdcc_gsinit_startup
    .globl __sdcc_program_startup
    .globl __start__stack
    .globl __mcs51_genXINIT
    .globl __mcs51_genXRAMCLEAR
    .globl __mcs51_genRAMCLEAR
    .area GSFINAL (CODE)
    ljmp __sdcc_program_startup
    ;--------------------------------------------------------
    ; Home
    ;--------------------------------------------------------
    .area HOME (CODE)
    .area CSEG (CODE)
    __sdcc_program_startup:
    lcall _main
    ; return from main will lock up
    sjmp .
    ;--------------------------------------------------------
    ; code
    ;--------------------------------------------------------
    .area CSEG (CODE)
    ;------------------------------------------------------------
    ;Allocation info for local variables in function 'idleTask'
    ;------------------------------------------------------------
    ;context Allocated to registers r2
    ;------------------------------------------------------------
    Ftest_00$idleTask$0$0 ==.
    C$test_00.c$2$0$0 ==.
    ; test_00.c:2: static unsigned char idleTask(unsigned char context) reentrant
    ; -----------------------------------------
    ; function idleTask
    ; -----------------------------------------
    _idleTask:
    ar2 = 0x02
    ar3 = 0x03
    ar4 = 0x04
    ar5 = 0x05
    ar6 = 0x06
    ar7 = 0x07
    ar0 = 0x00
    ar1 = 0x01
    ; genReceive
    mov r2,dpl
    C$test_00.c$4$1$1 ==.
    ; test_00.c:4: context++;
    ; genPlus
    ; genPlusIncr
    inc r2
    C$test_00.c$5$1$1 ==.
    ; test_00.c:5: return context;
    ; genRet
    mov dpl,r2
    ; Peephole 300 removed redundant label 00101$
    C$test_00.c$6$1$1 ==.
    XFtest_00$idleTask$0$0 ==.
    ret
    ;------------------------------------------------------------
    ;Allocation info for local variables in function 'mainLoop'
    ;------------------------------------------------------------
    ;context Allocated to registers r2
    ;------------------------------------------------------------
    Ftest_00$mainLoop$0$0 ==.
    C$test_00.c$8$1$1 ==.
    ; test_00.c:8: static void mainLoop() reentrant
    ; -----------------------------------------
    ; function mainLoop
    ; -----------------------------------------
    _mainLoop:
    C$test_00.c$10$1$1 ==.
    ; test_00.c:10: unsigned char context = 0;
    ; genAssign
    mov r2,#0x00
    C$test_00.c$11$1$1 ==.
    ; test_00.c:11: while (1)
    00102$:
    C$test_00.c$13$2$2 ==.
    ; test_00.c:13: context = idleTask(context);
    ; genCall
    mov dpl,r2
    lcall _idleTask
    mov r3,dpl
    ; genAssign
    mov ar2,r3
    ; Peephole 112.b changed ljmp to sjmp
    C$test_00.c$15$1$1 ==.
    XFtest_00$mainLoop$0$0 ==.
    sjmp 00102$
    ; Peephole 259.a removed redundant label 00104$ and ret
    ;
    ;------------------------------------------------------------
    ;Allocation info for local variables in function 'main'
    ;------------------------------------------------------------
    ;------------------------------------------------------------
    G$main$0$0 ==.
    C$test_00.c$17$1$1 ==.
    ; test_00.c:17: void main()
    ; -----------------------------------------
    ; function main
    ; -----------------------------------------
    _main:
    C$test_00.c$19$1$1 ==.
    ; test_00.c:19: mainLoop();
    ; genCall
    C$test_00.c$20$1$1 ==.
    XG$main$0$0 ==.
    ; Peephole 253.b replaced lcall/ret with ljmp
    ljmp _mainLoop
    ;
    .area CSEG (CODE)
    .area CONST (CODE)
    .area XINIT (CODE)
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.