>From memory, I think the Z80's SP=0 at reset, so the chances are that 
initialising of this register is something you're going to want to do fairly 
early on in your code.

There are a couple of ways at least of doing this, but I use my own crt0.s 
file and the --no-std-crt0 compiler switch. The other way is to modify the 
standard crt0.s and replace it with your own version (overwrite the standard 
one), and let the compiler switch default. You /could/ use a piece of inline 
asm in your main() to set SP too, but this is not very elegant because main() 
is itself a function call which would have had it's return address pushed 
onto the stack, albeit uninitialised. I recommend writing your crt0.s (copy 
the standard one and edit it for your own purposes), and manually relocate it 
yourself in your own build.

It might be useful for me to describe how SDCC handles Z80 initialisation - 
and this I have largely found out by experiment: The first to execute (from a 
reset) is crt0.s which will usually start at location 0x0000, the first three 
bytes will then be your reset jump instruction, probably a JMP to 0x0100 
(labelled 'init'), and then a bunch of definitions of your various restart 
vectors. At location 0x0100 you will probably want to set important registers 
such as SP and any MMU registers if you're using one of the weird 'enhanced' 
Z80's. After this there is a gsinit section (which is empty in crt0.s), into 
which the linker relocates global variable initialisation code if need be.

I have found that my init section doesn't appear in the linker's load map for 
some reason, but the code does appear in the eventual .hex file. Just a 
warning incase you're confused!

-- 
Richard.
PGP Key-id: 0x5AB3D350

Be free and open and breezy!  Enjoy!  Things won't get any better so
get used to it.

------------------------------------------------------------------------------
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to