Menu

#1 Relocation info

open
nobody
None
5
2005-07-20
2005-07-20
No

First: excellent work, k2asm is by far the best cross
assembler I've used. :)

One suggestion: I would really like k2asm to be able to
provide relocation for the code it generates (ideally
support an object code format including this). Fx, I've
written a C64 play routine and want to make a relocator
for it, so I need the indexes of all ORG-address
related data to be able to make the adjustments.

Regards

Discussion

  • Mads Orbesen Troest

    Logged In: YES
    user_id=317397

    Uhm, was supposed to read "... to provide relocation
    INFORMATION for the code ..." ;)

     
  • Zed Yago

    Zed Yago - 2006-03-16

    Logged In: YES
    user_id=1108496

    Thanks for the kind words!

    We have an ugly workaround for relocating code, I will post
    an example later here (using a Makefile and c64la).
    You are right, we need that relocation feature!

    The actual Problem (relocate a routine at runtime) can be
    done without assembler-relocation, if you use the *.hdr
    files right (i think)

     
  • Zed Yago

    Zed Yago - 2006-03-18

    Logged In: YES
    user_id=1108496

    k2asm v1.1 does not have a .reorg

    There are 2 types of relocation, assemble-time relocation
    and run-time
    relocation.

    Assemble-Time is needed, when your Program should be loaded
    into another
    memory, then it will run.

    Assemble-Time Relocation can be implemented with clever
    Makefiles.
    The main idea is to assemble the program into the
    run-location with .org and
    to use the c64la utility to change that address pefore
    linking it.

    Assemble-Time Relocation is also supported by many packers.

    Run-Time Relocation is most often used for music-play routines.
    The music-play routine is e.g. assembled and run at $1000.
    But because of certain memory-requirements, inside an
    Application, it should
    rather run at $C000.

    To implement this Feature i would suggest the following:

    1. .export all to be changed adresses in the play-routine.
    [code]
    ;player.src

    .org $1000
    .scope music {
    .export high10_01=*+2
    jmp init
    .export high10_02=*+2
    jmp play
    .export high10_03=*+2
    jmp exit
    }
    [/code]
    2. Put these words into a table, which _must_ be assembled
    after the
    playroutine.
    [code]
    ;reloctab.src

    #include "player.hdr"

    .org $0f00

    .word high10_01

    [/code]
    3. To relocate the program to e.g. $9000, copy the
    playroutine to $9000,
    then add to all addresses+$8000, which are in the table at
    $0f00, the value
    $80.
    This sounds more complicated then it is in 6502 :-)

    [code]
    ;copy the playroutine to $9000
    ldx#0
    {
    lda $1000,x
    sta $9000,x
    dex
    bne _cont
    }

    ;read address from reloctab and add $8000
    lda $0f00
    sta $fc
    lda $0f01
    clc
    adc#$80
    sta $fd

    ;change the playroutine at $9000
    ldy#0
    lda ($fc),y
    clc
    adc#$80
    sta ($fc),y

    ;repeat until all words in reloctab are processed

    [/code]

    Proposal for new relocation-directive in k2asm
    We can either use the standard 6502-Way, by assigning the
    programcounter.

    .org linktimeaddr
    *=runtimeaddr

    However, this breaks our internal styleguide, which looks
    like this:
    #include "local.inc"
    .org org.main
    That means that org.* is always the runtimeaddress, not the
    linktimeaddress.
    The linktimeaddress is assigned to reorg.*

    .reorg linktimeaddr
    .org runtimeaddr

    Howkey suggested, that we shall use just the .org directive
    several times:

    .org linktimeaddr
    .org runtimeaddr

    Please note that each syntax is possible, but we are not
    sure yet, which
    fits best...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.