Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

why unintialized stack errors?

why unintialized stack errors?

2007-01-02 by Thomas Keller

As far as I can see, I am initializing the stack point to RAMEND, but 
when i simulate this code, i am getting an uninitialized stack error 
when the rcall instrcution is hit.  Why for?


.include "tn25def.inc"

; Define here the variables
;
.def  temp  =r16

; Define here Reset and interrupt vectors, if any
;
RESET:
   rjmp START
   reti      ; Addr $01
   reti      ; Addr $02
   reti      ; Addr $03
   reti      ; Addr $04
   reti      ; Addr $05
   reti      ; Addr $06        Use 'rjmp myVector'
   reti      ; Addr $07        to define a interrupt vector
   reti      ; Addr $08
   reti      ; Addr $09
   reti      ; Addr $0A
   reti      ; Addr $0B        This is just an example
   reti      ; Addr $0C        Not all MCUs have the same
   reti      ; Addr $0D        number of interrupt vectors
   reti      ; Addr $0E
   reti      ; Addr $0F
   reti      ; Addr $10


; Program starts here after Reset
;
START:
 
;    this table povides the data for the intensity curve needed for
;    xxxxxxxxxxxxxxx.  the data represent the value sin^3 * 255 for
;    each angle from 0 through 90  at .9 degree increments

    .eseg

TABLE:
    .db    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 4, 5, 6, 6
    .db    8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24, 26, 29, 31, 34, 36
    .db    39, 44, 48, 52, 55, 59, 62, 66, 70, 74, 78, 82, 86, 90, 94, 99
    .db    103, 108, 112, 117, 121, 126, 130, 135, 140, 144, 149, 153
    .db    158, 163, 167, 172, 176, 180, 185, 189, 193, 197, 201, 205
    .db    209, 212, 216, 219, 223, 226, 229, 232, 234, 237, 239, 242
    .db    344, 346, 247, 249, 250, 252, 253, 254, 255, 255, 255
     
;
     .cseg


BEGIN:

    ldi    r30,    RAMEND                    ; initialize stack pointer
    out    SPL,    r30
   

    ldi    r31,    0x00                    ; set up EEPROM high byte address
    out EEARH,    r31                        ; store in register

    ldi    r31,    0x00                    ; set up upper WGM bytes
    out    WGM01,    r31                        ; and once again
    ldi    r31,    0x03                    ; set upo to set waveform 
configuration
    out    WGM00,    r31                        ; output to appropriate 
control register

;
;    set up timer delay for ~~.01 second
;
;    counter clock will be prescaled by 1024 to make the .01 second 
count easier
;

    ldi    r31,    0x38                    ;  load low byte of delay count
    out    TCNT0,    r31                        ; output to counter/timer 0-

    ldi    r31,    0xe5                    ; load the control value for 
TCCR1
                                        ; CTC1 set, PWMa set, COM1A set to
                                        ; toggle on match, timer clock set
                                        ; for system clock divided by 256

    out    TCCR1,    r31                    `    ; store in register

    ldi    r31,    0x01                    ; load value for TCCR01A
    out    TCCR0A,    r31                    ; and strope to TCCR01A
    ldi    r31,    0x04                    ; load value for TTCCR01B
    out    TCCR0B,    r31                    ; output to TCCR01B

    ldi    r31,        0x00                ; load compre output macthj value
    out    OCR0A,        r31                    ; stroe in output 
compare register 0A


;
;    this code sets the default initial table adress at -1.  It will 
automatically
;    increment on the first access, to 0
;

    ldi    r16,    0xff                    ; first addresss - 1 in 
EEPROM table data
    ldi r17,    0x00                    ; direction control byte, 0 = up

    rcall    TABLEDATA

    rjmp    DONE                        ; all done, leave
;
;    this subroutine counts up and down through the data table in the EEPROM
;    data, reading all 100 data values, from bottom to top, then top to 
bottom
;    one at a time
;

NEXT:

    ldi    r30,    0x00                    ; compare value
    cp    r17,    r30                        ; check direction bit for value
    brne    UP                            ; it's set for an up count
   
    ldi    r30,    0x00                    ; compare value
    dec    r16                                ; count the table pointer 
down one
    cp    r16,    r30                        ; at the bottom yet?
    ldi    r17,    0xff                    ; set direction flag to count up
    RJMP    QUIT0                        ; all done, depart

UP:
    ldi    r30,    0x63                    ; compare value
    inc    r16                                ; increment table pointer
    cp    r16,     r30                        ; 99 decimal, end of table
    breq    FIXIT0                        ; deal with table overflow
    rjmp    QUIT0                        ; all done, depart


FIXIT0:

    ldi    r17,    0x00                    ; reset direction flag for 
down count
           
QUIT0:

    ret                                    ; return from subrouttine 
call   

;
;    read a value from the EEPROM table
;

TABLEDATA:

    rcall    NEXT                        ; go grab next tabel address
    out    EEARL,     r16                    ; move table value address 
to EEPROM
                                        ; address register low byte
                                       
    in    r0,        EEDR                    ; read data from EEPROM 
data register
   
    ret                                    ; all done, go home   



DONE:
    rjmp DONE

    .exit

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by David VanHorn

I don't see what chip you're working with, but I only see SPL initted, not
SPH.




>
>    ldi    r30,    RAMEND                    ; initialize stack pointer
>    out    SPL,    r30



What I expect to see, is:

ldi TEMP,low(ramend)
out spl,TEMP
ldi TEMP,high(ramend)
out sph,TEMP


[Non-text portions of this message have been removed]

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by Zack Widup

I don't know but it looks to me like you're jumping to the table at the 
start of your program, not to BEGIN.  I think your first code line after 
RESET should be "rjmp BEGIN".

Your program is going to try to execute your table as code, and who knows 
where you will end up?

Zack
Show quoted textHide quoted text
On Tue, 2 Jan 2007, Thomas Keller wrote:

> 
> As far as I can see, I am initializing the stack point to RAMEND, but 
> when i simulate this code, i am getting an uninitialized stack error 
> when the rcall instrcution is hit.  Why for?
> 
> 
> .include "tn25def.inc"
> 
> ; Define here the variables
> ;
> .def  temp  =r16
> 
> ; Define here Reset and interrupt vectors, if any
> ;
> RESET:
>    rjmp START
>    reti      ; Addr $01
>    reti      ; Addr $02
>    reti      ; Addr $03
>    reti      ; Addr $04
>    reti      ; Addr $05
>    reti      ; Addr $06        Use 'rjmp myVector'
>    reti      ; Addr $07        to define a interrupt vector
>    reti      ; Addr $08
>    reti      ; Addr $09
>    reti      ; Addr $0A
>    reti      ; Addr $0B        This is just an example
>    reti      ; Addr $0C        Not all MCUs have the same
>    reti      ; Addr $0D        number of interrupt vectors
>    reti      ; Addr $0E
>    reti      ; Addr $0F
>    reti      ; Addr $10
> 
> 
> ; Program starts here after Reset
> ;
> START:
>  
> ;    this table povides the data for the intensity curve needed for
> ;    xxxxxxxxxxxxxxx.  the data represent the value sin^3 * 255 for
> ;    each angle from 0 through 90  at .9 degree increments
> 
>     .eseg
> 
> TABLE:
>     .db    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 4, 5, 6, 6
>     .db    8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24, 26, 29, 31, 34, 36
>     .db    39, 44, 48, 52, 55, 59, 62, 66, 70, 74, 78, 82, 86, 90, 94, 99
>     .db    103, 108, 112, 117, 121, 126, 130, 135, 140, 144, 149, 153
>     .db    158, 163, 167, 172, 176, 180, 185, 189, 193, 197, 201, 205
>     .db    209, 212, 216, 219, 223, 226, 229, 232, 234, 237, 239, 242
>     .db    344, 346, 247, 249, 250, 252, 253, 254, 255, 255, 255
>      
> ;
>      .cseg
> 
> 
> BEGIN:
> 
>     ldi    r30,    RAMEND                    ; initialize stack pointer
>     out    SPL,    r30
>    
> 
>     ldi    r31,    0x00                    ; set up EEPROM high byte address
>     out EEARH,    r31                        ; store in register
> 
>     ldi    r31,    0x00                    ; set up upper WGM bytes
>     out    WGM01,    r31                        ; and once again
>     ldi    r31,    0x03                    ; set upo to set waveform 
> configuration
>     out    WGM00,    r31                        ; output to appropriate 
> control register
> 
> ;
> ;    set up timer delay for ~~.01 second
> ;
> ;    counter clock will be prescaled by 1024 to make the .01 second 
> count easier
> ;
> 
>     ldi    r31,    0x38                    ;  load low byte of delay count
>     out    TCNT0,    r31                        ; output to counter/timer 0-
> 
>     ldi    r31,    0xe5                    ; load the control value for 
> TCCR1
>                                         ; CTC1 set, PWMa set, COM1A set to
>                                         ; toggle on match, timer clock set
>                                         ; for system clock divided by 256
> 
>     out    TCCR1,    r31                    `    ; store in register
> 
>     ldi    r31,    0x01                    ; load value for TCCR01A
>     out    TCCR0A,    r31                    ; and strope to TCCR01A
>     ldi    r31,    0x04                    ; load value for TTCCR01B
>     out    TCCR0B,    r31                    ; output to TCCR01B
> 
>     ldi    r31,        0x00                ; load compre output macthj value
>     out    OCR0A,        r31                    ; stroe in output 
> compare register 0A
> 
> 
> ;
> ;    this code sets the default initial table adress at -1.  It will 
> automatically
> ;    increment on the first access, to 0
> ;
> 
>     ldi    r16,    0xff                    ; first addresss - 1 in 
> EEPROM table data
>     ldi r17,    0x00                    ; direction control byte, 0 = up
> 
>     rcall    TABLEDATA
> 
>     rjmp    DONE                        ; all done, leave
> ;
> ;    this subroutine counts up and down through the data table in the EEPROM
> ;    data, reading all 100 data values, from bottom to top, then top to 
> bottom
> ;    one at a time
> ;
> 
> NEXT:
> 
>     ldi    r30,    0x00                    ; compare value
>     cp    r17,    r30                        ; check direction bit for value
>     brne    UP                            ; it's set for an up count
>    
>     ldi    r30,    0x00                    ; compare value
>     dec    r16                                ; count the table pointer 
> down one
>     cp    r16,    r30                        ; at the bottom yet?
>     ldi    r17,    0xff                    ; set direction flag to count up
>     RJMP    QUIT0                        ; all done, depart
> 
> UP:
>     ldi    r30,    0x63                    ; compare value
>     inc    r16                                ; increment table pointer
>     cp    r16,     r30                        ; 99 decimal, end of table
>     breq    FIXIT0                        ; deal with table overflow
>     rjmp    QUIT0                        ; all done, depart
> 
> 
> FIXIT0:
> 
>     ldi    r17,    0x00                    ; reset direction flag for 
> down count
>            
> QUIT0:
> 
>     ret                                    ; return from subrouttine 
> call   
> 
> ;
> ;    read a value from the EEPROM table
> ;
> 
> TABLEDATA:
> 
>     rcall    NEXT                        ; go grab next tabel address
>     out    EEARL,     r16                    ; move table value address 
> to EEPROM
>                                         ; address register low byte
>                                        
>     in    r0,        EEDR                    ; read data from EEPROM 
> data register
>    
>     ret                                    ; all done, go home   
> 
> 
> 
> DONE:
>     rjmp DONE
> 
>     .exit
>    
>

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by John Samperi

At 07:25 AM 3/01/2007, you wrote:

>RESET:
>    rjmp START
>
>; Program starts here after Reset
>;
>START:

The program ***CANNOT** start here. You are sending the program
to an address in EEPROM which contains a TABLE and not executable
code, apart from the fact that you ***CANNOT** run code from
EEPROM. Put the table in EESEG at the end of the program or change
the rest jmp to BEGIN rather than START.

You are probably confusing the daylight out of the assembler :)

>     .eseg
>
>TABLE:
>     .db    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 4, 5, 6, 6

I guess you must have read my other 2 emails as you have made some
changes to the code. We could fix some of the errors but then you
would not get much understanding of what's happening.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by Thomas Keller

Working with the Attiny25 (at25def.inc).     Which, according to the 
data sheet, has no SPH (only 128 Bytes of RAM).

David VanHorn wrote:
Show quoted textHide quoted text
>
> I don't see what chip you're working with, but I only see SPL initted, not
> SPH.
>
> >
> > ldi r30, RAMEND ; initialize stack pointer
> > out SPL, r30
>
> What I expect to see, is:
>
> ldi TEMP,low(ramend)
> out spl,TEMP
> ldi TEMP,high(ramend)
> out sph,TEMP
>
> [Non-text portions of this message have been removed]
>
> 
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.409 / Virus Database: 268.16.2/613 - Release Date: 1/1/2007
>

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by Thomas Keller

Yes, I  jave fixed that, and still I get the stack initialization 
error.  i have used the watch feature of the fdebugger, and in deed, my 
stack *IS* beingintialized, to the correct value (123 decimal, or 
0xdf).  So why is the simulator inissting that the stack is  uninitialized?


John Samperi wrote:
Show quoted textHide quoted text
>
> At 07:25 AM 3/01/2007, you wrote:
>
> >RESET:
> > rjmp START
> >
> >; Program starts here after Reset
> >;
> >START:
>
> The program ***CANNOT** start here. You are sending the program
> to an address in EEPROM which contains a TABLE and not executable
> code, apart from the fact that you ***CANNOT** run code from
> EEPROM. Put the table in EESEG at the end of the program or change
> the rest jmp to BEGIN rather than START.
>
> You are probably confusing the daylight out of the assembler :)
>
>

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by David VanHorn

Some have objected to this table, but the .eseg directive should result in
this table data being pulled into EEprom and not included in the hex that's
put in the program memory, so you should be executing ldi r30, ramend as the
first instruction.

Have you simmed it?


;
> RESET:
>   rjmp START
>   reti      ; Addr $01
>   reti      ; Addr $02
>   reti      ; Addr $03
>   reti      ; Addr $04
>
>
>
> ; Program starts here after Reset
> ;
> START:
>
>
>    .eseg
>
> TABLE:
>    .db    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 3, 4, 5, 6, 6
>    .db    8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 24, 26, 29, 31, 34, 36
>    .db    39, 44, 48, 52, 55, 59, 62, 66, 70, 74, 78, 82, 86, 90, 94, 99
>    .db    103, 108, 112, 117, 121, 126, 130, 135, 140, 144, 149, 153
>    .db    158, 163, 167, 172, 176, 180, 185, 189, 193, 197, 201, 205
>    .db    209, 212, 216, 219, 223, 226, 229, 232, 234, 237, 239, 242
>    .db    344, 346, 247, 249, 250, 252, 253, 254, 255, 255, 255
>
> ;
>     .cseg
>
>
> BEGIN:
>
>    ldi    r30,    RAMEND                    ; initialize stack pointer
>    out    SPL,    r30
>


[Non-text portions of this message have been removed]

Re: [AVR-Chat] why unintialized stack errors?

2007-01-02 by John Samperi

At 09:29 AM 3/01/2007, you wrote:
>So why is the simulator inissting that the stack is  uninitialized?

Have you read up about simulator "known issues" or BUGS? It may
be just that. May try it out later on today to see what I get.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] why unintialized stack errors?

2007-01-03 by John Samperi

At 09:29 AM 3/01/2007, you wrote:
>and still I get the stack initialization
>error.

I have just run your code with Studio without any error
of any kind. Do you have the latest Studio version and
patches?


Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] why unintialized stack errors?

2007-01-03 by Thomas Keller

/I don't know, John.  I'll go to atmel.com and check.  thank you.
tom

/
John Samperi wrote:
Show quoted textHide quoted text
>
> At 09:29 AM 3/01/2007, you wrote:
> >and still I get the stack initialization
> >error.
>
> I have just run your code with Studio without any error
> of any kind. Do you have the latest Studio version and
> patches?
>
> .

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.