Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Odd compile behavior or am I a rock?

Status
Not open for further replies.

MWostal

New Member
I am using the Microchips MPASM suite software, version 7.4. MPLAB IDE (fresh download and install of it).

I have compiled my sourcecode with 0 errors and warnings and have only the 2 expected messages about ensuring the correct banks are being used.

BUILD SUCCEEDED: Sat Nov 27 14:23:57 2006

My issue is when I attempt to use the simulator it always displays a stack overflow error as seen below.

CORE-E0002: Stack under flow error occurred from instruction at 0x000005

Using the program memory tool I find that the simulator is always starting at Address 0x000, my actual code starts at Address 0x0007 and I have instructed it to start at Address 0x0004. Below are the first lines from the program memory tool.

1 0000 3FFF ADDLW 0xff
2 0001 3FFF ADDLW 0xff
3 0002 3FFF ADDLW 0xff
4 0003 3FFF ADDLW 0xff
5 0004 3FFF ADDLW 0xff
6 0005 3400 RETLW 0
7 0006 3400 RETLW 0
8 0007 3000 MOVLW 0 ; This is the start of my code
9 0008 1683 BSF 0x3, 0x5

The actual start of my code is this

ORG 0x0004

MAIN CODE
movlw b'00000000' ; Define all zeros
bsf STATUS, RP0 ; Shift to bank 1

Why does the simulator start at 0000, my code start at 0007 and my ORG statement say 0x0004? Altering the ORG statement has no effect on the output of the compiler. My data section starts at 0x064 using the ORG 0x064 switch and it starts right where it should be. I have copied my program into a new Project using the 16f628 and I get the same indications when I build the project. Program starts at 0x007.

If I manually set the PC to 0x0007 the simulator runs beautifully without any errors (at least none for now :D). Any idea what I did wrong?

I can post the full program if needed or I can stand in an open field if all thats needed is beaning me with a few rocks :)
 
The simulator does exactly that, simulates a pic, and pics (nearly) always start execution at 0000. Just change your code to start at zero.

When you say your data is at 64, you can't just org 64, you have to use equates or cblock to define (ram) variables. If you mean fixed data in rom then you have to use the retlw instruction.

You might want to look at the sticky and follow one of the links to a tutorial.

Mike.
 
I understand the use of the simulator and I understand that on a reset or powerup the PC will point to address 0000. The issus is that I cannot change the start location by any means. ORG 0x0000, ORG 0x0004, ORG 0x0010 all have no effect on where my program actually starts. It always starts at 0x0007 and I cannot understand/find why it behaves this way.

My data is stored using the RETLW commands and the ORG statement just before the data behaves as you would expect. It puts the data sequencially starting at 0x0064 so I know the ORG directive is being seen its just being ignored at the beginning of my code.
 
The device Program Counter will be set to the reset vector address of h'00' or the last location of the memory depending on which chip you are using, upon any reset condition, therefore program execution starts there.
In the case of a chip without an internal oscillator calibration figure as set at the factory, the vector address will be zero, and for those devices with the internal calibration figure, the last memory location has a movlw h'calibration' figure and execution starts there, the device PC will roll round to h'00', the normal reset vector address.

If you want your code to actually begin execution starting at address h'07', simply put a label at where you wish your execution to start, and put a goto operand pointing to your label at address h'00', like this...


Code:
org h'00  ;reset vector address

goto start_here   ;this operand is at address h'00' because of the org directive above


org h'07'  ;start my code from here

start_here:   ;this label is at address h'07' because of the org directive above

blah             ;this operand is at address h'07'
blah blah       ;this one is at address h'08'


Your device will reset to the reset vector, h'00', then jump from h'00' to h'07' and begin executing your code.
 
Last edited:
Please understand, I thank you for your input and help but it is not addressing the actual problem. The problem is it does not use the ORG directive. I can't tell it to start at 0 at 10 or at 200. It starts at 0x0007 and if I put a goto command with an org 0x000 it will be placed at 0x0007.

I fully understand that the PC will start at 0x000, I just dont know why I cannot have my main program start at anything other than 0x0007.

Can it possibly be the linker or include file? Something is preventing the software from following the directive.
Below is the code as you describe.

org 0x0000
goto Main

org 0x0004 ; Start program here

; My working variables
Patt1 equ d'0' ; Start of Patterns
Patt2 equ d'8' ; pattern 2 offset
Patt3 equ d'16' ; pattern 3 offset
Patt4 equ d'24' ; pattern 4 offset
Patt5 equ d'32' ; pattern 5 offset
Outtime equ d'1' ; Outer time loop value
Intime equ d'3' ; Inner time loop value
; Set very low for stepping through
; the program for testing
cblock 0x20
CurPatt ; Current Pattern choice
Count ; 0 to 7, counter to restart
count1 ; Delay counter1
count2 ; Delay counter2
SwitchC ; Current value of switch counter (0-4)
endc

MAIN CODE
movlw b'00000000' ; Define all zeros

And the error code this causes....
Error[113] D:\MINE\PIC\PIC_16F84A_1\F84ATMPO.ASM 16 : Symbol not previously defined (Main)
Message[302] D:\MINE\PIC\PIC_16F84A_1\F84ATMPO.ASM 42 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] D:\MINE\PIC\PIC_16F84A_1\F84ATMPO.ASM 44 : Register in operand not in bank 0. Ensure that bank bits are correct.
Halting build on first failure as requested.
BUILD FAILED: Mon Nov 27 20:17:28 2006

If I leave out the first two lines it builds completely and work fine IF I manually set the PC to 0x0007 before I begin the simulator.
 
Last edited:
Ahhhh, your trying to use the code directive with fixed orgs. Just delete the code and data directives.

Mike.
 
The line that reads.....
MAIN code
is a line that if removed generates all kinds of build errors. It was in the template and I cannot remove it with errors. This appears (at least to me) that it must be there for the MPASM IDE build to function. Are you saying that its the cause of my troubles? If so then I guess its back to MPSAM helpfiles to find a way to remove it.

This is the error if I remove MAIN or even just code from the program.

Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x0000009c
Errors : 1


Okay, update on this issue.
I added the following.
org 0x0000
goto Start
org 0x0004
goto Start

and after the MAIN code section I added the label Start to the first line of code.
It now will put the goto start at 0 and at 04 but I had to add the label Start before it would work. The program is still starting at 0x0007 but I guess I will just leave it as at least it is building and working now.
 
Last edited:
You don't need the linker. Just use one of the templates in the C:\Program Files\Microchip\MPASM Suite\Template\Code folder and delete any references to a linker file in MPLAB. If your using a 16F628a then you should use f628atemp.asm.

HTH

Mike.
 
So its the link file that giving me grief? Thanks, thats one thing I can kill quickly! :)
I appreciate all the help!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top