[Sdcc-user] Z80 Assembly Development
Hello SDCC users, I'm doing a project with the famous Z80 just for fun, and decided to use the sdasz80 assembler. My project consists of multiple source files to keep everything modular. I'm having a problem with the linking step. I've 2 source files: boot.asm and numconv.asm: ; boot.asm: .globl HexToU8 .area _START (ABS) .org 0 ld SP, #0x call HexToU8 ... ; numconv.asm: .globl HexToU8 .area_CODE(REL,CON) HexToU8: ... ret As you can see, the boot.asm uses absolute placement because it needs to be placed at the begning of the memory (it needs to be executed first). The numconv.asm uses relative placement instead (it can be at any memory position provided that the HexToU8 symbol is correctly adjusted by the linker). To compile and link I invoke the folowing commands: $ sdasz80 -o src/numconv.asm $ sdasz80 -o src/boot.asm $ sdldz80 MemMonitor.ihx src/numconv.rel src/boot.rel -i $ sdobjcopy -Iihex -Obinary --pad-to 65536 --gap-fill 255 MemMonitor.ihx MemMonitor.bin It seems to compile and link fine, but the final binary doesn't include the numconv subroutines and the HexToU8 symbol assumes the value 0x. With my understanding the linker tries to put the _CODE (REL, CON) area at the 0x address, but it gets overwritten with the _START (ABS) area. How I tell the linker to put the _CODE area to any other available address (not used by the _START area)? -- ___ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user
Re: [Sdcc-user] Z80 Assembly Development
> Hello SDCC users, > > > I'm doing a project with the famous Z80 just for fun, and decided to use > the sdasz80 assembler. My project consists of multiple source files to > keep everything modular. I'm having a problem with the linking step. > I've 2 source files: boot.asm and numconv.asm: > > > ; boot.asm: > .globl HexToU8 > .area _START (ABS) > > .org 0 > ld SP, #0x > call HexToU8 > ... > > ; numconv.asm: > .globl HexToU8 > .area_CODE(REL,CON) > > HexToU8: > ... > ret > > > As you can see, the boot.asm uses absolute placement because it needs to > be placed at the begning of the memory (it needs to be executed first). > The numconv.asm uses relative placement instead (it can be at any memory > position provided that the HexToU8 symbol is correctly adjusted by the > linker). > > > To compile and link I invoke the folowing commands: > > $ sdasz80 -o src/numconv.asm > $ sdasz80 -o src/boot.asm > $ sdldz80 MemMonitor.ihx src/numconv.rel src/boot.rel -i > $ sdobjcopy -Iihex -Obinary --pad-to 65536 --gap-fill 255 MemMonitor.ihx > MemMonitor.bin > > > It seems to compile and link fine, but the final binary doesn't include > the numconv subroutines and the HexToU8 symbol assumes the value 0x. > With my understanding the linker tries to put the _CODE (REL, CON) area > at the 0x address, but it gets overwritten with the _START (ABS) > area. How I tell the linker to put the _CODE area to any other available > address (not used by the _START area)? I'd start by linking boot.rel first. Maarten -- ___ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user
Re: [Sdcc-user] Z80 Assembly Development
I've tried what you suggested, linking the boot.rel first results in the opposite effect, the _START area gets overwritten by the _CODE area. Here a small showcase for the problem I'm having: ; boot.asm: .globl HexToU8 .area _START (ABS,OVR) .org 0 ldSP, #0x call HexToU8 Loop: jpLoop .asciz"boot" ; numconv.asm: .globl HexToU8 .area _CODE (REL,CON) HexToU8: ldA, #'A' ret TESTSTR: .asciz"numconv" $ sdasz80 -o numconv.asm $ sdasz80 -o boot.asm $ sdldz80 MemMonitor.ihx boot.rel numconv.rel -i $ sdobjcopy -Iihex -Obinary --pad-to 65536 --gap-fill 255 MemMonitor.ihx MemMonitor.bin $ hexdump -C MemMonitor.bin 3e 41 c9 6e 75 6d 63 6f 6e 76 00 6f 74 00 ff ff |>A.numconv.ot...| 0010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff || * 0001 As you can see, the linker overwrites the _START area with the _CODE area. On 17-08-2016 11:09, Maarten Brock wrote: >> Hello SDCC users, >> >> >> I'm doing a project with the famous Z80 just for fun, and decided to use >> the sdasz80 assembler. My project consists of multiple source files to >> keep everything modular. I'm having a problem with the linking step. >> I've 2 source files: boot.asm and numconv.asm: >> >> >> ; boot.asm: >> .globl HexToU8 >> .area _START (ABS) >> >> .org 0 >> ld SP, #0x >> call HexToU8 >> ... >> >> ; numconv.asm: >> .globl HexToU8 >> .area_CODE(REL,CON) >> >> HexToU8: >> ... >> ret >> >> >> As you can see, the boot.asm uses absolute placement because it needs to >> be placed at the begning of the memory (it needs to be executed first). >> The numconv.asm uses relative placement instead (it can be at any memory >> position provided that the HexToU8 symbol is correctly adjusted by the >> linker). >> >> >> To compile and link I invoke the folowing commands: >> >> $ sdasz80 -o src/numconv.asm >> $ sdasz80 -o src/boot.asm >> $ sdldz80 MemMonitor.ihx src/numconv.rel src/boot.rel -i >> $ sdobjcopy -Iihex -Obinary --pad-to 65536 --gap-fill 255 MemMonitor.ihx >> MemMonitor.bin >> >> >> It seems to compile and link fine, but the final binary doesn't include >> the numconv subroutines and the HexToU8 symbol assumes the value 0x. >> With my understanding the linker tries to put the _CODE (REL, CON) area >> at the 0x address, but it gets overwritten with the _START (ABS) >> area. How I tell the linker to put the _CODE area to any other available >> address (not used by the _START area)? > I'd start by linking boot.rel first. > > Maarten > > > -- > ___ > Sdcc-user mailing list > Sdcc-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sdcc-user -- ___ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user
Re: [Sdcc-user] Z80 Assembly Development
While I don't have sdcc loaded at the moment, and haven't used it for Z80, isn't the OVR in .area _START (ABS,OVR) indicating that that segment can be overlayed (which is not what you want)? I'd check the linker manual or just try removing it and see if your problem goes away. Peter Van Epp On Wed, Aug 17, 2016 at 11:01:05PM -0300, Augusto Fraga Giachero wrote: > I've tried what you suggested, linking the boot.rel first results in the > opposite effect, the _START area gets overwritten by the _CODE area. > Here a small showcase for the problem I'm having: > > > ; boot.asm: > .globl HexToU8 > .area _START (ABS,OVR) > > .org 0 > ldSP, #0x > call HexToU8 > -- ___ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user