tane Posted June 20, 2021 Share Posted June 20, 2021 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 Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted June 20, 2021 Share Posted June 20, 2021 Try just "sta label". Does this work? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 20, 2021 Share Posted June 20, 2021 ldx #5 lda #ea loop sta label,x dex bpl loop Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted June 20, 2021 Share Posted June 20, 2021 TGB1718: You forgot the $ in "lda #$ea" Quote Link to comment Share on other sites More sharing options...
tane Posted June 20, 2021 Author Share Posted June 20, 2021 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? Quote Link to comment Share on other sites More sharing options...
fantômas Posted June 20, 2021 Share Posted June 20, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 20, 2021 Share Posted June 20, 2021 1 hour ago, Harry Potter said: TGB1718: You forgot the $ in "lda #$ea" Just testing you , passed with flying colours Quote Link to comment Share on other sites More sharing options...
+slx Posted June 20, 2021 Share Posted June 20, 2021 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? 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? Quote Link to comment Share on other sites More sharing options...
tane Posted June 20, 2021 Author Share Posted June 20, 2021 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. Quote Link to comment Share on other sites More sharing options...
+slx Posted June 21, 2021 Share Posted June 21, 2021 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? Quote Link to comment Share on other sites More sharing options...
+slx Posted June 21, 2021 Share Posted June 21, 2021 Assembles fine on MAC/65. Quote Link to comment Share on other sites More sharing options...
sanny Posted June 21, 2021 Share Posted June 21, 2021 what assembler are you using? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 21, 2021 Share Posted June 21, 2021 if it's ca65, labels must have a : after the name lda stuff and #1 bne l1 lda #0 sta $cb l1: lda #3 sta $cc RTS .endproc stuff: .byte 0 Quote Link to comment Share on other sites More sharing options...
tane Posted June 21, 2021 Author Share Posted June 21, 2021 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... Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted June 21, 2021 Share Posted June 21, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
fantômas Posted June 21, 2021 Share Posted June 21, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
tane Posted June 21, 2021 Author Share Posted June 21, 2021 (edited) 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 June 21, 2021 by tane Quote Link to comment Share on other sites More sharing options...
fantômas Posted June 21, 2021 Share Posted June 21, 2021 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. Quote Link to comment Share on other sites More sharing options...
pps Posted June 21, 2021 Share Posted June 21, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
tane Posted June 21, 2021 Author Share Posted June 21, 2021 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. Quote Link to comment Share on other sites More sharing options...
+slx Posted June 21, 2021 Share Posted June 21, 2021 Wow, I wasn't aware assemblers could do locally scoped labels at all. I obviously need to write longer assembler programs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.