2

Recently I have started making code on 6502-based systems, and I have used the ca65 macro assembler. However I found out that it supports procedures using .proc . So I have been wondering what is the difference between these blocks of code:

mainLabel:
    jsr subroutine

subroutine:
    ;Code
    rts

and this code:

mainLabel:
    jsr procedure

.proc procedure
    ;Code
    rts
.endproc

When I try running my programs using these 2 syntaxes I seem to get the same result. From what I can tell from the ca65 documentation, procedures prevent code from outside it from entering labels within it.

  • 4
    `.proc` makes labels inside the procedure private, so other code can't access them (without explicitly adding the procedure). The code generated is the same, but it protects you from accidentally jumping into the middle, etc. because of for example a typo in that other code. It helps prevent bugs, and lets you re-use local labels if you want to have something like "build_return_value" as a label in more than one procedure – Dave S Feb 03 '23 at 19:36
  • 2
    Docs are [here](https://www.cc65.org/doc/ca65-11.html#.PROC). – larsks Feb 03 '23 at 19:39

1 Answers1

0

It's the same as far as the CPU is concerned. The benefit to using .proc is so that you can use common label names like loop, again, etc. locally in multiple different functions without the assembler throwing a fit that you used the same label twice. Otherwise you'd have to come up with increasingly contrived label names for every function you write. (Trust me, I've been there.) Let the computer do that for you!

puppydrum64
  • 1,598
  • 2
  • 15