where the assembly program begin at?

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

where the assembly program begin at?

6,006 Views
pele
Contributor I
I am a beginer to HC08 assembly language. I wonder how to define the begining code for an assembly program? Does it begin with "main:", like java? are there reference .pdf files coverring the assembly programming of HC08?  
Labels (1)
0 Kudos
Reply
6 Replies

1,546 Views
eckhard
Contributor V

Hello,

 

it works like this :

 

*** Memory Definitions****************************************************

ROM            equ    $8000               ;start of Flash mem
RAM             equ    $80                    ;start of RAM mem
VectorStart  equ  $FFDC         ; Interrupt Vectors

Set your Rom Adress

set your starting adress for the code

*** MAIN ROUTINE *********************************************************

                ORG    ROM              ; start am annfang des FLASH ROMs

                lda    InitConfig1      ; Configregister Schreiben
                sta    CONFIG1

here comes the rest of your code

then set your vectors

**************************************************************
* Vectors                                                    *
*                                                            *
**************************************************************
   org  VectorStart

        dw  dummy_isr    ; Time Base Vector
        dw  dummy_isr    ; ADC Conversion Complete
        dw  dummy_isr    ; Keyboard Vector
        dw  dummy_isr    ; SCI Transmit Vector
        dw  dummy_isr    ; SCI Receive Vector
        dw  dummy_isr    ; SCI Error Vector
        dw  dummy_isr    ; SPI Transmit Vector
        dw  dummy_isr    ; SPI Receive Vector
        dw  dummy_isr    ; TIM2 Overflow Vector
        dw  dummy_isr    ; TIM2 Channel 1 Vector
        dw  dummy_isr    ; TIM2 Channel 0 Vector
        dw  dummy_isr    ; TIM1 Overflow Vector
        dw  dummy_isr    ; TIM1 Channel 1 Vector
        dw  dummy_isr    ; TIM1 Channel 0 Vector
        dw  dummy_isr    ; PLL Vector
        dw  dummy_isr    ; IRQ1 Vector
        dw  dummy_isr    ; SWI Vector
        dw  ROM    ; Reset Vector

The reset vector points to the rom entry which is your Program start.

 

Eckhard

0 Kudos
Reply

1,546 Views
pele
Contributor I
Thanks! A further question:
    Since the main routine entry must be unique in a whole assembly program,  does it follow that the "ORG"  can  be used only one time in an assembly program? 
0 Kudos
Reply

1,546 Views
peg
Senior Contributor IV

Hi pele,

No, not quite!

ORG means origin, it simply means place the following code at this starting address. You can use it as many times as you like.

The reset vector defines the "entry point" and often is an address that has been used in an ORG statement but not necessarily.

You can see Eckard's example used it twice!

Regards David

 

0 Kudos
Reply

1,546 Views
pele
Contributor I
peg, Thank you very much!
    With your clear correction and eckhard's sample program,  together with the reference I have, my new understanding is as follows:
   An assembly program first begins runing with the contents at the address of $FFFE and $FFFF, called Reset Vector. In eckhard's sample program, the contents of Reset Vector is ROM, so the program is redirected to run at the address of ROM, which is also defined as the starting address of the main routine. Till now, the related instructions have done nothing but change the content of the program counter.
    is my new understanding conrrect?
 
0 Kudos
Reply

1,546 Views
bigmac
Specialist III

Hello Pele,

Your understanding is correct - the contents of all vectors are simply program counter values to represent the beginning of a specific section of code.  However, it would be more usual to identify the start of the program with a meaningful label.  For example,
       org ROM+$100
START: ; Commence initialisation code here

 

Within the vector table:

       dc.w  START  ; Reset vector

In this case, the label START is more meaningful than ROM+$100.  Note that I have used dc.w rather than dw, for compatibility with Code Warrior.

Regards,
Mac

 

0 Kudos
Reply

1,546 Views
pele
Contributor I
Hi eckhard, peg and bigmac,
    Thank all of you for your help and kindness. With your help, my hard question was solved. Furthermore, your reply taught me more than what I asked. bigmac, for the difference between dw and dc.w you mentioned, I will remind myself when I use CodeWarrior. 
 
Best Regards!
 
pele
 
0 Kudos
Reply