6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 7:56 am

All times are UTC




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Fri Jan 12, 2024 9:20 pm 
Offline

Joined: Sun Aug 28, 2022 7:30 pm
Posts: 25
BigDumbDinosaur wrote:
6502user wrote:
Hi.

Can you help me also, please?

I'm starting to compile some code with the CCA65's CA65. When I compile it without MAcros, all is working ok. But if I use macros the macros don't be compiled (but the process don't give error.

Are you compiling C code, or are you assembling?  Compiling and assembling are two different things.


I'm assembling. Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 9:29 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
(Could you post your code in [code] tags to preserve indentation?)


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 12, 2024 10:10 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1398
Location: Scotland
It looks like they are being assembled to me:


6502user wrote:
Hi. My code is:

ca65 V2.19 - Git 28f892b
Main file : src/Test_new.a65
Current file: src/Test_new.a65

000000r 1
000000r 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
000000r 1 ;PSUMLP -- Page sum macro
000000r 1 ;
000000r 1 ;pre: X contains 0
000000r 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
000000r 1 .macro SUM ADDR
000000r 1 .local PSUMLP
000000r 1 PSUMLP: CLC
000000r 1 ADC ADDR,X
000000r 1 INX
000000r 1 BNE PSUMLP
000000r 1 .endmacro
[/code]


e.g. here in the listing:

Quote:
Code:
     
00F04A  1  A2 00           LDX    #$00                        
00F04C  1  A9 00           LDA    #$00                        
00F04E  1  18 7D 00 F0     SUM   $F000                  
00F052  1  E8 D0 F9     


the SUM macro is expanded.

So I'm not sure what the issue is here.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 11:45 am 
Offline

Joined: Sun Aug 28, 2022 7:30 pm
Posts: 25
Hi, again.

I thought that when assembling the macro, a subroutine was generated that was embedded in some free area of ​​memory. So I was looking for that subroutine that was obviously nowhere to be found. What happens is that the code resulting from the macro is embedded in the program code itself every time the macro is invoked. And that makes more sense than my idea (although it takes up more memory).

So reviewing the list produced by ca65 when assembling the source, yes, indeed the macros were embedded there.

This is the code I tried to assemble (thanks, Gordon):

.macro waitBaud
.local loop
ldy $EA
loop: dey
bne loop
.endmacro

.ORG $F000

START: SEI

NOP
NOP
NOP
waitBaud; Delay 1 bit time
NOP
waitBaud; Delay 1 bit time

.segment "VECTORS"
.ORG $FFFA
.word START
.word START
.word START


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 11:49 am 
Offline

Joined: Sun Aug 28, 2022 7:30 pm
Posts: 25
And this is the list resulting from assembling it:

ca65 V2.19 - Git 28f892b
Main file : trial.a65
Current file: trial.a65

000000r 1
000000r 1 ;.segment "CODE"
000000r 1
000000r 1 .macro waitBaud
000000r 1 .local loop
000000r 1 ldy $EA
000000r 1 loop: dey
000000r 1 bne loop
000000r 1 .endmacro
000000r 1
000000r 1 .ORG $F000
00F000 1
00F000 1 78 START: SEI
00F001 1
00F001 1 EA NOP
00F002 1 EA NOP
00F003 1 EA NOP
00F004 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
00F008 1 FD
00F009 1 EA NOP
00F00A 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
00F00E 1 FD
00F00F 1
00F00F 1 .segment "VECTORS"
00F00F 1 .ORG $FFFA
00FFFA 1 00 F0 .word START
00FFFC 1 00 F0 .word START
00FFFE 1 00 F0 .word START
00FFFE 1


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 12:00 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1398
Location: Scotland
6502user wrote:
And this is the list resulting from assembling it:

ca65 V2.19 - Git 28f892b
Main file : trial.a65
Current file: trial.a65

000000r 1
000000r 1 ;.segment "CODE"
000000r 1
000000r 1 .macro waitBaud
000000r 1 .local loop
000000r 1 ldy $EA
000000r 1 loop: dey
000000r 1 bne loop
000000r 1 .endmacro
000000r 1
000000r 1 .ORG $F000
00F000 1
00F000 1 78 START: SEI
00F001 1
00F001 1 EA NOP
00F002 1 EA NOP
00F003 1 EA NOP
00F004 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
00F008 1 FD
00F009 1 EA NOP
00F00A 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
00F00E 1 FD
00F00F 1
00F00F 1 .segment "VECTORS"
00F00F 1 .ORG $FFFA
00FFFA 1 00 F0 .word START
00FFFC 1 00 F0 .word START
00FFFE 1 00 F0 .word START
00FFFE 1



That's essentially what I'd expect. Macros are expanded in-line with your code, making it larger, subroutines aren't.

So you need to think about where you place the subroutines then JSR to them and end them with an RTS - there is no magic/automatic conversion of macros into subroutines. (it can be done, but you need to DIY it)

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 4:56 pm 
Offline
User avatar

Joined: Thu Mar 24, 2022 8:52 pm
Posts: 10
6502user wrote:
And this is the list resulting from assembling it:
[...]
00F004 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
00F008 1 FD
00F009 1 EA NOP
00F00A 1 A4 EA 88 D0 waitBaud; Delay 1 bit time
[...]

Please also note this PR https://github.com/cc65/cc65/pull/2279, which wants to add the expansion of macros in the listing file.

Unfortunately, this will not add the comments, as it re-creates the "source" be printing what the parsed macro already contains.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2024 8:35 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8428
Location: Southern California
6502user wrote:
I thought that when assembling the macro, a subroutine was generated that was embedded in some free area of ​​memory. So I was looking for that subroutine that was obviously nowhere to be found. What happens is that the code resulting from the macro is embedded in the program code itself every time the macro is invoked. And that makes more sense than my idea (although it takes up more memory).

That's what a macro is.  The following is from the front page of the macros section of my site, the first couple of paragraphs under "First, what is an assembly-language macro?":

    As you write an assembly-language program, you may see repeating patterns.  If it's exactly the same all the time, you can make it a subroutine.  That incurs a 12-clock performance penalty for the subroutine call (JSR) and return (RTS), but program memory is saved because the code for the subroutine is not repeated over and over.

    There will be other times however where the repeating pattern is the same but internal details are not, so you can't just use a JSR.  The differences from one occurrence to another might be an operand, a string or other data, an address, a condition, etc..  It would be helpful to be able to tell the assembler, "Do this sequence here; except when you get down to this part, substitute-in such-and-such," or, "under such-and-such condition, assemble this alternate code."  That's where it's time for a macro.  "White Flame" on the 6502.org forum wrote, "Macros are assembly-time function calls, whose return value is source code."


As a side note, 6502user, you can put [code] and [/code] around your code to preserve the white space and force monospacing.  I sent a PM about this.  It would be good to click on "User Control Panel" (in the top-right corner of your screen), then "Board preferences" (on the left edge of the screen), then where it says "Notify me on new private messages:" and the line below it, "Pop up window on new private message:", make sure the "Yes" buttons are clicked.  And before you post, click "Preview" under the box where you write your post, to make sure it will look the way you intended.  You can also edit your post after it's already posted, by clicking "Edit".

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: