EdouardBERGE / rasm

RASM powerful Z80 assembler
132 stars 16 forks source link

Recommended way to give a proximity label to a placeholder #28

Closed anrikun closed 2 years ago

anrikun commented 2 years ago

Currently this is how I give a label to a placeholder (self-modifying code):

subroutine1
  ;
  ; Some code
  ;
myval = $+1 : ld a,0
  ;
  ; Some code
  ;
  ld hl,myval 
  inc (hl)
  ;
  ; Some code
  ;
  ret 

The problem is that myval here is not a proximity label but a global variable. I would like to give a proximity label to my placeholder.

Obviously I could do something like:

.myval ld a,0
;
ld hl,.myval+1

or

defb 0x3E ; Opcode for LD A,n
.myval defb 0
;
ld hl,.myval

But none of these solutions satisfies me.

Maybe there's a way to do what I want but I couldn't figure it out. Any idea?

EdouardBERGE commented 2 years ago

you may use a proximity alias

ld a,0 : .myval equ $-1 ld hl,.myval

advantage is that you could use .myval before it's declared

anrikun commented 2 years ago

Wow, great solution! Thank you for your help as always, Edouard.

anrikun commented 2 years ago

Actually there are downsides to all solutions so far: Placeholder does not get a real label so it doesn't show up as a symbol when debugging with Winape. I end up with ld (#08AD),a instead of ld (.myval),a

I've found another workaround:

org $+1 : .myval : org $-1
ld a,0

Not very easy to read but it works...