Jump to content
IGNORED

How to get the address of a label?


Recommended Posts

How to get the address of a label?:

 

As example: the following placed somewhere in the code:

label
  sta $20
  sta $21
  sta $22
;end of label

 

Then if at some point of the execution it's required to change the contents to nop, i.e.: all previous 6 bytes inside "label" to "ea":

  lda #$ea
  sta         ; -> but how to know automatically the address where "label" is

 

Link to comment
Share on other sites

46 minutes ago, Harry Potter said:

Try just "sta label".  Does this work?

 

5 minutes ago, TGB1718 said:

        ldx #5

        lda #ea

loop sta label,x

       dex

       bpl loop

 

 

It does not work just making a "sta label", it says it's "undeclared label".

Note: the "sta label" it's being executed inside the code of a function, previously called by a jsr. Are the externals labels hidden inside the function?

 

label.png.9bfff3376edfbe29b0a74992aa286eea.png

 

 

 

Link to comment
Share on other sites

You can also use a variation of the old "BIT trick" I suppose.  

This allows you to easily restore the original code: you replace STA instruction opcode by BIT instruction opcode to alter and the reverse to restore.

But beware: a BIT instruction used in this way as a NOP does have effects: the flags may be modified!!

 

myproc  .proc 
        ; ---
label
        sta $20
        sta $21
        sta $22
        ; ---
        rts
        .endp 
        
alter_myproc    .proc
        lda #$24        ;  $24= BIT Zero Page, e.g  BIT $44 
        sta myproc.label
        sta myproc.label+2
        sta myproc.label+4
        rts 
        .endp 

restore_myproc    .proc
        lda #$85        ;  $85= STA Zero Page, e.g  STA $44 
        sta myproc.label
        sta myproc.label+2
        sta myproc.label+4
        rts 
        .endp 

 

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, tane said:

 

 

It does not work just making a "sta label", it says it's "undeclared label".

Note: the "sta label" it's being executed inside the code of a function, previously called by a jsr. Are the externals labels hidden inside the function?

 

label.png.9bfff3376edfbe29b0a74992aa286eea.png

 

 

 

Assemblers usually do not care about scope. I don‘t see why it wouldn‘t recognise label. Have you used it twice by any chance?

Link to comment
Share on other sites

8 minutes ago, slx said:

Have you used it twice by any chance?

No.. in that case it'll show a "warning".

 

I'll try fantomas idea, but not sure if it work because in this case the more code is added (or cpu used) the more glitches appear, so I'm thinking the way to just make a "turn on/off" for a " jmp exit". It's possible to do it at the end when everything is finished and the address where it was placed is known, but I'd like a way to know the address where the statement is placed, in order to point it automatically.

 

Link to comment
Share on other sites

8 hours ago, tane said:

No.. in that case it'll show a "warning".

 

I'll try fantomas idea, but not sure if it work because in this case the more code is added (or cpu used) the more glitches appear, so I'm thinking the way to just make a "turn on/off" for a " jmp exit". It's possible to do it at the end when everything is finished and the address where it was placed is known, but I'd like a way to know the address where the statement is placed, in order to point it automatically.

 

Have you tried just those snippets on a different (emulated) assembler?

Link to comment
Share on other sites

5 hours ago, sanny said:

what assembler are you using?

It's MADS, latest version (CRC32: 24a7ea98). (It's shown in the command line in the black screenshot).

 

10 hours ago, slx said:

Have you tried just those snippets on a different (emulated) assembler?

No, I only manage its syntax...

 

Link to comment
Share on other sites

This version that inserts a 'jmp label2' compiles with mads. 

  • alter_myproc use global exit.it.is
  • alter_myproc2 use local label 

But at the end it is exactly the same...

 

          org $2000

myproc  .proc 

label
.def :exit.it.is = *
        ; ---
        sta $20
        sta $21
        sta $22
label2
        rts
        .endp 

alter_myproc    .proc
        mva #$4C exit.it.is                        ; $4c = JMP opcode
        mwa #myproc.label2 exit.it.is+1
        rts 
        .endp 

alter_myproc2    .proc
        mva #$4C myproc.label                       ; $4c = JMP opcode
        mwa #myproc.label2 myproc.label+1
        rts 
        .endp 

 

 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, TGB1718 said:

just had a look at the MADS documentation it looks like you use 

EQU or .DEF for global variables, have a look here for examples

 

https://mads.atari8.info/mads_eng.html#labels

 

17 minutes ago, fantômas said:

label .def :exit.it.is

 

Yeah, making a "  .def :label" did the trick, now it compiles and works, thank you.

 

It seems that everything inside a jsr is treated as local, so external labels are hidden. With the .def now is defined as global and works when calling a jsr.

 

The Mads documentation says:

 

Global labels

Each definition outside of a macro (.MACRO), procedure (.PROC), or local scope (.LOCAL) is global.

 

It should be required to add that a jsr is treated as local, and not global.

 

Edited by tane
Link to comment
Share on other sites

17 minutes ago, tane said:

Global labels

Each definition outside of a macro (.MACRO), procedure (.PROC), or local scope (.LOCAL) is global.

 

It should be required to add that a jsr is treated as local, and not global.

 

 

I think that if your label is not global, it proves that it is defined either:

  • in a macro
  • or in a procedure
  • or in a 'local' scope

For a procedure or for a local scope, you can use the notation (with the dot) "procname". "labelname" or "localname". "labelname" to use the label globally.

 

Link to comment
Share on other sites

If you want do call a label within a subroutine, you have to add the subroutine's name in front. 

 

Example:

   org $2000

.local mysub
label1
   lda #$24
   sta 712
   rts
.endl

.proc main
   jsr mysub
   mva #$fe 19
@  lda 19
   bmi @-
   sta mysub.label1+1
   jsr mysub
lp jmp lp
.endp

   run main

 

  • Like 1
Link to comment
Share on other sites

38 minutes ago, fantômas said:
  • or in a procedure

After a look, that's right, in a procedure of 4000 lines... The .endp was almost lost at the end, and the open/close fold display was not showing properly in UEStudio because the code has many labels ended in .end, so the "close fold" didn't end in the .endp.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...