TGB1718 Posted December 9, 2022 Share Posted December 9, 2022 Maybe it's me, but I can't get MADS to compile any code that tries to use parameters, I'm not using registers variables, just want to pass normal variables in. I checked the MADS documents and surprisingly most of the examples don't work. Using something like :- myproc .PROC (.WORD par1 .BYTE par2) It says Undeclared Macro Using:- myproc .PROC (.WORD par1 .BYTE par2) .VAR and it passes that in the compile, but when I try using the variables passed in lda par1 ldx par2 .endp it says Undeclared label par1 and Undeclared label par2 At this point I'm only trying to create the procedure, not got far enough to figure out how to call it. Anyone have a simple piece of code that might give me a clue what I'm doing wrong. I don't have any issues with procedures without parameters. thanks in advance Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted December 9, 2022 Share Posted December 9, 2022 if you are not using .reg then you also need to define: @proc_vars_adr = $80 e.g. from the hex.asm example: // after declaring the procedure .PROC with parameters, execution is automatically forced // macros @PULL, which will remove the parameters from the program stack for us and put them in memory // from the address @PROC_VARS_ADR, the label of the LOW parameter is assigned the address @PROC_VARS_ADR or from the plot.asm example, using .reg you can use: .proc plot (.word xa .byte y) .reg sta tmp1 stx tmp1+1 and define your 'tmp1' variable yourself Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 9, 2022 Author Share Posted December 9, 2022 @Wrathchild thanks for your reply, although it didn't fix the problem, it did give me some clues on how to fix the problem. I tried compiling the hex.asm and it did no problems, I added a dummy procedure, same as the one I was attempting in my code and it worked, same code in my project fails, with a bit of poking and prodding I found that you need to add some MACRO definitions which are in the MACROS folder under examples. To create a procedure with parameters you need to add ICL '@pull.mac' that made my code compile. I got errors when I tried to call the procedure and to fix that you need to add ICL '@call.mac' that compiled ok but then I had a strange error on a branch instruction in my code that made no sense however including:- ICL '@exit.mac' Fixed the compile error and didn't seem to make any difference to the code generated A quick play and it does seem to pass the variables in ok, the code looks a bit messy as it's putting a lot of macro code in to access the variables. Again, many thanks I can now make some headway Quote Link to comment Share on other sites More sharing options...
tebe Posted December 10, 2022 Share Posted December 10, 2022 myproc .PROC (.WORD par1 .BYTE par2) .VAR .var par1 .word .var par2 .byte lda par1 ldx par2 .endp or myproc .PROC (.WORD par1+1 .BYTE par2+1) .VAR par1 lda $1000 par2 ldx #0 .endp or myproc .PROC (.WORD par1 .BYTE par2) .VAR lda par1: $1000 ldx par2: #0 .endp or myproc .PROC (.WORD xy .BYTE a) .reg .endp An example program using the .PROC procedure declaration and the MADS software stack https://github.com/tebe6502/Mad-Assembler/blob/master/examples/hex.asm https://github.com/tebe6502/Mad-Assembler/blob/master/examples/proc_rekurencja.asm Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 10, 2022 Author Share Posted December 10, 2022 Thanks @tebe , that's the one I looked at and noticed the ICL statements at the bottom of the listing, might have been more useful to put them at the top of the example Without those included macro's it just doesn't work 1 Quote Link to comment Share on other sites More sharing options...
Steril707 Posted December 12, 2022 Share Posted December 12, 2022 Interestingly, I don't get any of the reference's examples for using Macros with parameters to work. If I use this example, I just get a "label 'val' is not defined" or something like that error (am at work now, so not sure about the wording). .macro SetColor val,reg lda :val sta :reg .endm Macros without parameters work without problems, though. So, what am I doing wrong here? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 12, 2022 Author Share Posted December 12, 2022 (edited) Macro's are fine, they are a very different beast. All assemblers that I know of can use Macros, but they can't use Procedures (obviously some can) Macros are generated each time you use one, so if you have 10 instances of the same Macro it is generated 10 times so your code is larger, but probably runs more quickly. Procedures are compiled once , however when you use procedures the compiler has to use macros to provide a software stack for the parameters. But what I've noticed is because the added macros to make the stack and then use that stack in the procedure, it makes the code much bigger than you would expect. Each call to the procedure again uses Macro expansion to make each call, so even though there is only 1 procedure, there is a quite big overhead to make the call, the more parameters, the bigger (and slower) the code. Apart from making the source code very readable, I don't see much benefit in using them. Also a final point, readability of the generated code when using Procedures is "quite messy" and bears little resemblance to what you would expect, where as Macro's generate nice tidy code. Edit: Should have said, maybe using registers in the procedure calls for passing variables is more efficient, not tried it yet Edited December 12, 2022 by TGB1718 Quote Link to comment Share on other sites More sharing options...
danwinslow Posted December 12, 2022 Share Posted December 12, 2022 Not sure what the point of procedures is in this situation. I doubt you're getting (or would want) stack recursion and 'local' variables, and from the description it sounds like it's just adding extra code and possibly execution time. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 12, 2022 Author Share Posted December 12, 2022 55 minutes ago, danwinslow said: and from the description it sounds like it's just adding extra code and possibly execution time. That's exactly it 👍 Quote Link to comment Share on other sites More sharing options...
tebe Posted December 12, 2022 Share Posted December 12, 2022 (edited) 3 hours ago, TGB1718 said: Also a final point, readability of the generated code when using Procedures is "quite messy" and bears little resemblance to what you would expect, where as Macro's generate nice tidy code. Edit: Should have said, maybe using registers in the procedure calls for passing variables is more efficient, not tried it yet is an exceptional case when macros are used normally macros are not used for procedures (.VAR, .REG) Edited December 12, 2022 by tebe 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.