News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

relocatable assemblers

Started by arnoldemu, 13:23, 13 August 09

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

arnoldemu

I am looking for an assembler that can generate relocatable code preferably a PC based one.
Any ideas? Thanks.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: arnoldemu on 13:23, 13 August 09
I am looking for an assembler that can generate relocatable code preferably a PC based one.
Any ideas? Thanks.
I will answer my question a bit:

as-z80 comes with sdcc and can generate relocate data that as-link can use.
but to get relocatable files for cpc you need my patches over the top for this to work.
The problem with this one is the syntax for ld a,(ix+0) is actually ld a,0(ix) crazy!

z80asm comes with z88dk and can also generate relocatable data.. but I've not yet looked at this in detail.

Basically I am looking for assemblers that can generate simple relocation data which is fast to parse. I think it looks like I may settle with z80asm.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

fano

Hi,

afaik Winape assembleur can generate relocatable code, maybe maxam too
"NOP" is the perfect program : short , fast and (known) bug free

Follow Easter Egg products on Facebook !

Executioner

Quote from: fano on 17:01, 13 August 09
afaik Winape assembleur can generate relocatable code, maybe maxam too

WinAPE can, Maxam can't. The commands used are:

relocate_start
relocate_end
relocate_table [byte|word] [address]

[/]
There are also a couple of variables defined relocate_count and relocate_size. Basically, relocate_start marks the start of a relocatable code section, relocate_end marks the end, and relocate_table generates the relocation table. By default, it's simply a list of 16 bit words specifying the offset in the code of another word each, but for small code, you can create a byte table using relocate_table byte.

Usually, you'd also use dw relocate_count somewhere.

arnoldemu

Quote from: Executioner on 15:15, 14 August 09
WinAPE can, Maxam can't. The commands used are:

relocate_start
relocate_end
relocate_table [byte|word] [address]

[/]
There are also a couple of variables defined relocate_count and relocate_size. Basically, relocate_start marks the start of a relocatable code section, relocate_end marks the end, and relocate_table generates the relocation table. By default, it's simply a list of 16 bit words specifying the offset in the code of another word each, but for small code, you can create a byte table using relocate_table byte.

Usually, you'd also use dw relocate_count somewhere.
Ahh.. I read this in the winape documentation but still I do not understand fully what winape will do.
So it generates a list of words. relocate_count is the number of words and relocate_size is the size of all the data?
Ok, so does it handle both code and data, and also what if I code this:

ld l,addr AND 255
ld h,addr/256

does it handle this? And if so, how is the data stored...
Please can I have an example source and example assembled file.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Executioner

Quote from: arnoldemu on 16:58, 14 August 09
Ok, so does it handle both code and data, and also what if I code this:

ld l,addr AND 255
ld h,addr/256

does it handle this? And if so, how is the data stored...

Unfortunately, it doesn't handle the above. It's just a table of offsets to words within the code, including the data. Maybe I can add support for msb and lsb relocate tables.

The following code will generate a relocation table at the end of the code:


org #4000

relocate_start

.move_data
ld hl,data1
ld de,data2
ld bc,6
ldir
ret

.data1 dw move_data, data2, 0
.data2 ds 6

relocate_end

dw relocate_count
relocate_table


The relocate table should contain the offsets of #4001, #4004, #400c and #400e

Longshot

Hi

I'm not sure that that kind of relocate table is very useful or easy to use.
Probably yes if the purpose is the creation of a library but not, in my opinion, to create in the same code more than one instance of the same routine.

It miss something very useful and no so much complicated to do i think : (thank you very much mr wilson  ;D)
The ability to assembly a code to an address defined for another address. (like the A2 dams option)

May be by adding a new parameter in ORG directive.
For example :

            ORG #A000, #2000
            LD HL, RHAAA
RHAAA NOP

           ORG $,#3000
           LD A,(GRUIK)
GRUIK
           LD DE,RHAAA
           ORG $
           LD A,TABLE
TABLE DB 0

This will create
#A000 LD HL,#2003
#A003 NOP
#A004 LD A,(#3003)
#A007 LD DE,#2003
#A00B LD A,#0D
#A00D

$ to indicate the current 1st assembly address.
It will be easiest to create a compact code and avoid the mathematical address relocations :
EXECADDR   EQU #4000
       ORG #1000
       LD HL,CODE
       LD DE,EXECADDR
      LD BC,ENDCODE-CODE
      LDIR
       JP EXECADDR
CODE
       LD HL,(DATA-CODE+EXECADDR)
       JP HERE-CODE+EXECADDR
HERE
       JR $
DATA DB #FF
ENDCODE
Rhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!

Executioner

Quote from: Longshot on 08:56, 17 August 09
I'm not sure that that kind of relocate table is very useful or easy to use.

It's useful, so long as you don't use page-aligned code or tables. Hopefully, I can add that functionality also.

QuoteThe ability to assembly a code to an address defined for another address. (like the A2 dams option)

Isn't that the same as the Maxam second ORG parameter, as has always been supported by WinAPE (but I think the parameters are reversed)?

Longshot

QuoteIsn't that the same as the Maxam second ORG parameter, as has always been supported by WinAPE (but I think the parameters are reversed)?

Oupss you're right. Sorry to re invent the wheel  ::)
(indicated here http://cpcrulez.free.fr/coding_maxamDOC.htm)

In my previous example, we would to have
ORG #2000,#A000
But is it possible to have
ORG #3000,$ or ORG $

Useful if you have multiple relative code to assemble at #A000 for example..
Rhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!

Executioner

Quote from: Longshot on 10:22, 19 August 09
But is it possible to have
ORG #3000,$ or ORG $

WinAPE (not sure about Maxam) has two predefined variables, one is $ - the current code address, and the other is @ - the current code output address (controlled by the second parameter of org).

I think what you're looking for is


org $,#3000    ; Generate code at #3000, current origin
org $         ; Generate code at correct (current) address

Powered by SMFPacks Menu Editor Mod