Author Topic: relocatable assemblers  (Read 3813 times)

0 Members and 1 Guest are viewing this topic.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2280
  • Likes Given: 3478
relocatable assemblers
« on: 15:23, 13 August 09 »
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

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2280
  • Likes Given: 3478
Re: relocatable assemblers
« Reply #1 on: 17:10, 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

Offline fano

  • Supporter
  • 6128 Plus
  • *
  • Posts: 835
  • Country: fr
  • Easter Egg Programmer
    • Easter Egg
  • Liked: 278
  • Likes Given: 614
Re: relocatable assemblers
« Reply #2 on: 19:01, 13 August 09 »
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 !

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 392
  • Likes Given: 60
Re: relocatable assemblers
« Reply #3 on: 17:15, 14 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.
 

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2280
  • Likes Given: 3478
Re: relocatable assemblers
« Reply #4 on: 18:58, 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

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 392
  • Likes Given: 60
Re: relocatable assemblers
« Reply #5 on: 05:06, 17 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:

Code: [Select]
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

Offline Longshot

  • Supporter
  • CPC664
  • *
  • Posts: 105
  • Country: fr
    • Logon System Web Site
  • Liked: 111
  • Likes Given: 23
ORG evolution ?
« Reply #6 on: 10:56, 17 August 09 »
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
Rhaaaaaa

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 392
  • Likes Given: 60
Re: ORG evolution ?
« Reply #7 on: 10:10, 19 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.

Quote
The 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)?

Offline Longshot

  • Supporter
  • CPC664
  • *
  • Posts: 105
  • Country: fr
    • Logon System Web Site
  • Liked: 111
  • Likes Given: 23
Re: relocatable assemblers
« Reply #8 on: 12:22, 19 August 09 »
Quote
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)?

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..
Rhaaaaaa

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 392
  • Likes Given: 60
Re: relocatable assemblers
« Reply #9 on: 02:34, 21 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

Code: [Select]
org $,#3000    ; Generate code at #3000, current origin
org $         ; Generate code at correct (current) address