Help me pick an assembler!

Programming the 6502 microprocessor and its relatives in assembly and other languages.
6502user
Posts: 33
Joined: 28 Aug 2022

Re: Help me pick an assembler!

Post by 6502user »

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.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Help me pick an assembler!

Post by BigEd »

(Could you post your code in

Code: Select all

 tags to preserve indentation?)
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Help me pick an assembler!

Post by drogon »

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
e.g. here in the listing:
Quote:

Code: Select all

      
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/
6502user
Posts: 33
Joined: 28 Aug 2022

Re: Help me pick an assembler!

Post by 6502user »

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
6502user
Posts: 33
Joined: 28 Aug 2022

Re: Help me pick an assembler!

Post by 6502user »

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
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Help me pick an assembler!

Post by drogon »

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/
User avatar
strik
Posts: 14
Joined: 24 Mar 2022

Re: Help me pick an assembler!

Post by strik »

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.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Help me pick an assembler!

Post by GARTHWILSON »

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?
Post Reply