6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 2:29 am

All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 9:06 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
My As65 assembler adds an alphabetically sorted (left column) and numerically sorted (right column) symbol dump to the end of the listing file
Code:
Portable 65xx Assembler [14.05.19]

Symbol Table

ACIA_CMND                        0000FE02  | MB_IMP                           00000000
ACIA_CTRL                        0000FE03  | MD_IMP                           00000000
ACIA_DATA                        0000FE00  | NUL                              00000000
ACIA_STAT                        0000FE01  | OP_NUL                           00000000
ACK                              00000006  | __6501__                         00000000
A_REG                            000000F0  | __65816__                        00000000
BEL                              00000007  | __65832__                        00000000
BRKHandler                       0000F039  | __65C02__                        00000000
BS                               00000008  | __65SC02__                       00000000
Bits                             0000F466  | MB_ACC                           00000001
BumpPtr                          0000F591  | MD_ACC                           00000001
BumpRx                           0000FF54  | SOH                              00000001
BumpTx                           0000FF5C  | __6502__                         00000001

External refernces show as zero (as they are unknown at assembly time) and relocatable symbols will show as the offset to the section start address. The map file generated by the linked shows where the external symbols and sections were finally placed.
Code:
Global Symbol Map

GetChar           0000F5F8 in boot.obj


Sections:

.page0           : 000000F0 - 000000FD in boot.obj
.bss             : 00000200 - 00000300 in boot.obj
.code            : 0000F000 - 0000F6A8 in boot.obj
                   0000FC00 - 0000FDFF in boot.obj
                   0000FE00 - 0000FEFF in boot.obj
                   0000FF00 - 0000FF64 in boot.obj
                   0000FFFA - 0000FFFF in boot.obj

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 4:06 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
BigEd wrote:
But note my subsequent post!

Noted. I saw it after the fact. :oops:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 4:08 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
BitWise wrote:
My As65 assembler adds an alphabetically sorted (left column) and numerically sorted (right column) symbol dump to the end of the listing file
Code:
Portable 65xx Assembler [14.05.19]

Symbol Table

ACIA_CMND                        0000FE02  | MB_IMP                           00000000
ACIA_CTRL                        0000FE03  | MD_IMP                           00000000
ACIA_DATA                        0000FE00  | NUL                              00000000
ACIA_STAT                        0000FE01  | OP_NUL                           00000000
ACK                              00000006  | __6501__                         00000000
A_REG                            000000F0  | __65816__                        00000000
BEL                              00000007  | __65832__                        00000000
BRKHandler                       0000F039  | __65C02__                        00000000
BS                               00000008  | __65SC02__                       00000000
Bits                             0000F466  | MB_ACC                           00000001
BumpPtr                          0000F591  | MD_ACC                           00000001
BumpRx                           0000FF54  | SOH                              00000001
BumpTx                           0000FF5C  | __6502__                         00000001

External refernces show as zero (as they are unknown at assembly time) and relocatable symbols will show as the offset to the section start address. The map file generated by the linked shows where the external symbols and sections were finally placed.
Code:
Global Symbol Map

GetChar           0000F5F8 in boot.obj


Sections:

.page0           : 000000F0 - 000000FD in boot.obj
.bss             : 00000200 - 00000300 in boot.obj
.code            : 0000F000 - 0000F6A8 in boot.obj
                   0000FC00 - 0000FDFF in boot.obj
                   0000FE00 - 0000FEFF in boot.obj
                   0000FF00 - 0000FF64 in boot.obj
                   0000FFFA - 0000FFFF in boot.obj

One of these days I'm going to see about getting your assembler up and running on my (one and only) Windows box. I'm not a fan of Java, as it tends to be quite the resource hog. However, your assembler's design is well thought out and has plenty of functionality.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 7:37 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
BigDumbDinosaur wrote:
One of these days I'm going to see about getting your assembler up and running on my (one and only) Windows box. I'm not a fan of Java, as it tends to be quite the resource hog. However, your assembler's design is well thought out and has plenty of functionality.


Java runs on other operating systems, not just Windows. It works very nicely on Linux.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 8:02 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Works on OSX too, with a suitable command line:
java -cp ../65xx.jar uk.co.demon.obelisk.w65xx.As65 IsDigit.asm


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 9:29 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
BitWise wrote:
Java runs on other operating systems, not just Windows. It works very nicely on Linux.


Attached is a ZIP with the latest JAR and some example files configured for *NIX.


Attachments:
File comment: *NIX version of Dev65
Dev65.zip [494.18 KiB]
Downloaded 66 times

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Fri Aug 15, 2014 11:27 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 395
Location: Minnesota
Quote:
My As65 assembler adds an alphabetically sorted (left column) and numerically sorted (right column) symbol dump to the end of the listing file


Ooh, I like the two column idea. HXA puts those one after the other, which seemed reasonable but I like your idea better. I will investigate how easy it would be to...uh...borrow that :P


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Sun Aug 17, 2014 7:22 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 395
Location: Minnesota
Quote:
I emailed the author but didn't expect a response since he has stopped maintaining it. He explained that the address in the listing is the address before the command is evaluated. The macro changes the address with .org but it is already too late at that point.

It doesn't look like there is any way to do what I'm trying to do, at least with this assembler.


Sure there is. The answer is right there. Here's your original macro:

Quote:
.macro var name,address
name=address
.org address
.res 1 ;reserve one byte
.endmacro

.org $2000
var foo,$3000
var bar,$3001


When "foo" is invoked the value of the program counter is $2000, so that's what it is when "name=address" is encountered. So that's what you see in the listing.

"foo" then sets the program counter to $3000 and adds one by virtue of ".res 1". So when "bar" is invoked the value of the program counter is $3001 when "name=address" is encountered. So that's what you see.

You see? "bar" shows the value you expect not because it does anything differently than "foo", but because a side effect of invoking "foo" is to set the program counter to that value.

You should re-arrange the body of the macro so that the program counter has the value you want when "name=address" is encountered. Say, by moving the ".org" line before it.


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Sun Aug 17, 2014 7:47 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Edit - ignore this post, I was mistaken!

Unfortunately, it seems not to be that easy. The address as reported in the listing doesn't respond to changes to * within macros, even though all the machinery is proceeding as it should:

Code:
000000r 1               .feature pc_assignment
000000r 1               
000000r 1               .macro var name,address
000000r 1                  .local tmp_star
000000r 1                  tmp_star=*
000000r 1                  *=address
000000r 1                  .res 1 ;reserve one byte
000000r 1                  .export name:=*
000000r 1                  *=tmp_star
000000r 1               .endmacro
000000r 1               
000000r 1               *=$2000
002000  1               
002000  1               .data
002000  1  xx           var foo,$3000
002000  1  xx           var bar,$3001
002000  1               
002000  1               tmp_star=*
002000  1               *=$3002
003002  1  xx           .res 1
003003  1               .export baz:=*
003003  1               *=tmp_star
002000  1               
002000  1               .code
002000  1               
002000  1               start:
002000  1  EA            nop
002001  1  AD 01 30      lda foo
002004  1  8D 02 30      sta bar
002007  1  60            rts


Last edited by BigEd on Sun Aug 17, 2014 7:50 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Sun Aug 17, 2014 7:49 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Oops, sorry, you're quite right - I was being too clever in restoring * within the macro.

Edit: double oops, this actually shows that there's still a problem. The listing shows the address before the macro executes.

Code:
000000r 1               .feature pc_assignment
000000r 1               
000000r 1               .macro var name,address
000000r 1                  .local tmp_star
000000r 1                  tmp_star=*
000000r 1                  *=address
000000r 1                  .res 1 ;reserve one byte
000000r 1                  .export name:=*
000000r 1               ;  *=tmp_star
000000r 1               .endmacro
000000r 1               
000000r 1               .data
000000r 1  xx           var foo,$3000
003001  1  xx           var bar,$3001
003002  1               
003002  1               tmp_star=*
003002  1               *=$3002
003002  1  xx           .res 1
003003  1               .export baz:=*
003003  1               *=tmp_star
003002  1               
003002  1               .code
003002  1               
003002  1               *=$2000
002000  1               
002000  1               start:
002000  1  EA            nop
002001  1  AD 01 30      lda foo
002004  1  8D 02 30      sta bar
002007  1  60            rts
002007  1


Last edited by BigEd on Sun Aug 17, 2014 8:52 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Sun Aug 17, 2014 8:07 pm 
Offline
User avatar

Joined: Mon May 12, 2014 6:18 pm
Posts: 365
Quote:
You should re-arrange the body of the macro so that the program counter has the value you want when "name=address" is encountered. Say, by moving the ".org" line before it.

This has no effect. Remember when I said this:
Quote:
He explained that the address in the listing is the address before the command is evaluated.

By command I meant the macro itself. In the example the address $2000 is output to the file even before the macro is evaluated.


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Sun Aug 17, 2014 10:29 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 395
Location: Minnesota
Okay, I see the problem. But first, I think this:

Code:
000000r 1               .macro var name,address
000000r 1                  .local tmp_star
000000r 1                  tmp_star=*
000000r 1                  *=address
000000r 1                  .res 1 ;reserve one byte
000000r 1                  .export name:=*
000000r 1               ;  *=tmp_star
000000r 1               .endmacro


should be this:

Code:
000000r 1               .macro var name,address
000000r 1                  .local tmp_star
000000r 1                  tmp_star=*
000000r 1                  *=address
000000r 1                  .export name:=*
000000r 1                  .res 1 ;reserve one byte
000000r 1               ;  *=tmp_star
000000r 1               .endmacro


in order to match the original macro. As written these values seem one higher than they ought:

Code:
002000  1               start:
002000  1  EA            nop
002001  1  AD 01 30      lda foo
002004  1  8D 02 30      sta bar
002007  1  60            rts


I note that this (non-macro) code shows exactly the behavior I suggested, as far as addresses go:

Code:
003002  1               tmp_star=*
003002  1               *=$3002
003002  1  xx           .res 1
003003  1               .export baz:=*
003003  1               *=tmp_star
003002  1               


Presumably the macro invocations are doing the same thing internally, but the only address that gets shown is the value at the start of the macro invocation. Which is a reasonable choice; the program counter can have multiple values during the expansion, but on one line the listing can only show one in any case.

So I amend my suggestion to include displaying all the lines of the macro expansion, not just the one that invoked it. I don't see any obvious way to do that with ca65, but I don't know it intimately so there may be one.


Top
 Profile  
Reply with quote  
 Post subject: Re: CA65: .org in .macro
PostPosted: Mon Aug 18, 2014 12:48 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Indeed, a more verbose form of listing would do the trick, but I didn't see how to do that.
Cheers
Ed


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 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: