program counter & reset vector

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

program counter & reset vector

3,369 Views
zen
Contributor I
Hi,
   I am a HC08 beginner.  I wonder how the contents of Program Counter and RESET Vector ($FFFE,$FFFF) are set at the beging of a program.  Below is where the question stems from.
 
   I created a project with CW. In the automatic created file " INCLUDE 'derivative.inc" has this code:
        ROMStart:           equ   $00008000
        INT_RESET:       equ   $0000FFFE
 
   in the automatic created main.asm has this code:
 
      ; Include derivative-specific definitions
         INCLUDE 'derivative.inc'
      ; export symbols
            XDEF _Startup
            ABSENTRY _Startup
 
      ; variable/data section
           ORG    RAMStart         ; Insert your data definition here
           ExampleVar: DS.B   1
           TEMP1: EQU $0040

           ; code section
             ORG    ROMStart
_Startup:
             LDHX   #RAMEnd+1        ; initialize the stack pointer
            TXS
            CLI                     ; enable interrupts
mainLoop:
           
            ; Insert your code here
            NOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
When simulating this program in CW, I found that both the contents of PC (program counter) and $FFFE,$FFFF are 8000.  I wonder how each content of the two is set?
 
Thanks!
zen
  
Labels (1)
0 Kudos
Reply
4 Replies

1,529 Views
rocco
Senior Contributor II
Hi Zen,

The RESET vector, $FFFe:#FFFF, is in flash memory, and is programmed to point to the starting address of your code when you program your flash memory.

Then, as the chip comes out of RESET, the contents of $FFFE:$FFFF are copied into the program counter, to cause you program to start execution at the starting address of your code.

Hope that helps.
0 Kudos
Reply

1,529 Views
CompilerGuru
NXP Employee
NXP Employee
if the question is where the 0xfffe bytes come from, then look further down the main.asm.

For absolute assembly projects with no device init support,
is the reset vector set further down in main.asm

Code: end of main.asm
            ORG   $FFFA            DC.W  spurious          ;            DC.W  spurious          ; SWI            DC.W  _Startup          ; Reset


Daniel
 


0 Kudos
Reply

1,529 Views
zen
Contributor I
Thank you, rocco and Daniel.
     I realize now that the initial content at $FFFE,$FFFF are set at the time of programing the flash memory by some kind of progrmmer, and are determined by 
                          "DC.W  Startup          ; Reset"
after programming the chip and power off the chip, the content of Reset vector still keep its value as being programmed.
    Now, my remain question is about the content of PC. PC is in CPU, not in flash memory, so it is impossible to set its value as progrmming the chip.  If each time powering on the chip generates a Reset condition, then it is understandable that the content at $FFFE,$FFFF will be loaded to PC. But it is hard for me to understand that the assumption is reasonable. 
 
   Thanks
    zen
0 Kudos
Reply

1,529 Views
zen
Contributor I
From a reference book, I find that, power-on does create a reset, called Power-on Reset, POR, the result is that PC is loaded with the content of Reset vector. It should be where your porgram begins. 
0 Kudos
Reply