Simulator and ATmega48 Stack Pointer

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using the AVR simulator II, at reset the stack pointer is 0x4FF (correct). After my code, it is 0xFF. TEMP register shows correct values.

What am I missing?

RESET:							;

;
;--------------------------------------------------------------------------
;

	cli							;NO INTERRUPTS

;
;--------------------------------------------------------------------------
;

	in TEMP, MCUCR				;			

	mov saveMCUCR, TEMP			; Store MCUCR for future reference in debug

	ldi TEMP, 0x00				;

	out MCUCR, TEMP				; Reset MCUCR flags



	ldi TEMP, high(RAMEND)	;Set stack pointer to the end of memory
							;  S/B 0x04
	out SPH, TEMP			;
	
	ldi TEMP, low (RAMEND)	;  S/B 0xFF
	
	out SPL, TEMP			;RAMEND S/B 0x02FF   
							; simulator SP = Xx00FF

John

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

0x4FF is not correct - 0x2FF is. When I build and run this in the simulator 2:

	.include "m48def.inc"

	.def	TEMP = R16
	.def	saveMCUCR = R17

RESET:                     ; 
; 
;-------------------------------------------------------------------------- 
; 
   cli                     ;NO INTERRUPTS 
; 
;-------------------------------------------------------------------------- 
; 

   in TEMP, MCUCR            ;          
   mov saveMCUCR, TEMP         ; Store MCUCR for future reference in debug 
   ldi TEMP, 0x00            ; 
   out MCUCR, TEMP            ; Reset MCUCR flags 

   ldi TEMP, high(RAMEND)   ;Set stack pointer to the end of memory 
   out SPH, TEMP         ; 
   ldi TEMP, low (RAMEND)   ;  S/B 0xFF 
   out SPL, TEMP         ;RAMEND S/B 0x02FF    
                     ; simulator SP = Xx00FF
   nop

as the simulator starts with the yellow arrow on the "cli" the Stack Pointer display shows the expected 0x2FF (not 0x4FF). If I then single step to the "nop" I added (what did you think it would do after the "out SPL"?) then, as expected the stack pointer display shows 0x2FF

Either you built for the wrong processor (wrong .include) or you are simulating the wrong processor (selected the on Debug menu with "Select platform and device).

Cliff

PS I guess there's an outside possibility your Studio+assembler is out of date - I use 4.18.716 - aka "SP3"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Cliff. I forgot I changed to an ATmega88 and never relabeled the schematic. When I changed the simulator platform to ATmega88, it worked.

I don't think I ever would have found it alone. The obvious stuff seems to bite me pretty hard once in a while.

John