Macro/Function Pseudo Instructions Everyone Should Use?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BigEd »

I tried to build, but didn't quite make it. I've contacted the owner of a fork on their Github issue. (Tragically, Andrew passed away earlier this month, so we will need third-party assistance. It would be great to have this project of his available as a runnable release.)
Oh-Two
Posts: 7
Joined: 13 Jan 2021

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by Oh-Two »

Oh my goodness, that's terrible. I had no idea. I've benefitted considerably from his work in both hardware and software, which he gave to the public so generously.

My condolences to his family and friends. A really sad loss to all of those who interacted with him here.
User avatar
cjs
Posts: 759
Joined: 01 Dec 2018
Location: Tokyo, Japan
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by cjs »

Oh-Two wrote:
I've downloaded Andrew Jacob's Dev65 assembler...But I can't figure out how to run it!
This is entirely unrelated to the topic of this thread, so perhaps you could repost your query as the start of a new thread? (I suggest copying the contents of your post here to a new post and editing the one here to point to it.)

I don't mind helping out with some answers, but there's likely to be a lot of back-and-forth that will not be of any interest at all to many readers of this thread.
Curt J. Sampson - github.com/0cjs
Gungwald
Posts: 2
Joined: 21 Aug 2021
Location: Columbus, Ohio USA
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by Gungwald »

BigEd wrote:
I tried to build, but didn't quite make it. I've contacted the owner of a fork on their Github issue. (Tragically, Andrew passed away earlier this month, so we will need third-party assistance. It would be great to have this project of his available as a runnable release.)
I'm the owner of the fork. I will create a buildable version and a runnable release. Sorry to hear about Andrew. That is a terrible loss.
User avatar
Proxy
Posts: 746
Joined: 03 Aug 2018
Location: Germany

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by Proxy »

Not sure it's something everyone should be using, but personally i added some alternative instruction mnemonics to make them more readable.
specifically for INC, DEC, CL*, SE*, PH*, and PL*
examples:

Code: Select all

PHA
PLP
CLC
INX
DEY
SEI
etc
can be turned into:

Code: Select all

PSH A
PLL P
CLR C
INC X
DEC Y
SET I
etc
it's especially noticable with the NotePad++ highlighting i'm using for Assembly:
notepad++_2021-08-21_23-13-31.png
I also got the good old "ADD" and "SUB" Pseudo Instructions which assemble into "CLC ADC" and "SEC SBC" respectively.

and just for fun, and becuase i often hear people compare the Zeropage to a RISC CPU's Register File i added a bunch of RISC-like instructions that actually use the Zeropage as it's Register file. it also predefines some constants so you can use R0-R255 to refer to decimal 0-255, making the RISC Experience even more immersive!
notepad++_2021-08-21_23-08-52.png
maybe one day i'll make a 65C02 FPGA Core around this idea.
fachat
Posts: 1123
Joined: 05 Jul 2005
Location: near Heidelberg, Germany
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by fachat »

Agumander wrote:
One assembler feature I've been wondering exists anywhere is using "{" as label to the next instance of "}", with the ability to nest them.
(It could be some other pair of demarcating characters, those are just the first I think of as a C guy)
This would save me from having to come up with unique label names, or avoid bugs that happen if i miscount bytes when writing BEQ *+n
Had this happen on my current project when I forgot that one of my named memory locations wasn't actually zero page. Oops!
You mean like the .( and .) Block pseudo opcodes of xa65? Ca65 has similar functionality just can't remember right now the names
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BillG »

Proxy wrote:
Not sure it's something everyone should be using, but personally i added some alternative instruction mnemonics to make them more readable.
If your assembler does not supply them, define the following aliases:

BLO for BCC
BHS for LCS

Code: Select all

    cmp     #Value
    blo     Label
is more obvious than

Code: Select all

    cmp     #Value
    bcc     Label
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by GARTHWILSON »

BillG wrote:
is more obvious than
I guess I need some interpretation.  BLO looks like "below;" but then BHS should be something like "Same as or above," but it doesn't look anything like that.  Whatever it is, it's certainly not obvious.  And what is LCS?  I can't think of what that might be.  Again, definitely not obvious.  The aliases I've seen are BLT (branch if less than) for BCC, and BGE (branch if greater than or equal).

Edit, addition:  In my program flow-control structure macros, what I would do for the CMP #value, BCC <label> is something like:

Code: Select all

        CMP  #value
        IF_GE             ; If it was greater than or equal to the value,
            <do_stuff>    ; do this stuff.
            <do_stuff>
        END_IF

and the IF_GE assembles the BCC down to the END_IF.  It leaves a dummy byte for the branch distance, and that byte gets filled in by the END_IF later when it is encountered during assembly.  No label is needed.  These are nestable too, with more structures of the same or different kind.
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?
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BillG »

These are from the Motorola instruction sets.

BLT, BLE, BGT, BGE are for use after signed comparision.

BLO (LOwer), BLS (Lower or Same), BHI (Higher) and BHS (Higher or Same) are the unsigned counterparts.

MOS may not have adopted those out of "copyright" concerns.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by GARTHWILSON »

Ah, that makes sense, although require a small amount of learning if one has not come from the other processors.  I added to my post above while you were posting.
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?
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BillG »

GARTHWILSON wrote:
In my program flow-control structure macros, what I would do for the CMP #value, BCC <label> is something like:

Code: Select all

        CMP  #value
        IF_GE             ; If it was greater than or equal to the value,
            <do_stuff>    ; do this stuff.
            <do_stuff>
        END_IF
and the IF_GE assembles the BCC down to the END_IF. It leaves a dummy byte for the branch distance, and that byte gets filled in by the END_IF later when it is encountered during assembly. No label is needed. These are nestable too, with more structures of the same or different kind.
You still have the signed vs unsigned conundrum. Is GE signed or unsigned?

You can choose different phrases or add a suffix: GES and GEU
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by GARTHWILSON »

For that, I think your signed comparison with the EOR #$80's would come before the IF, like the CMP above comes before the IF.  I don't think I have ever done signed for 8-bit numbers though, only 16 or more.
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?
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BigDumbDinosaur »

BillG wrote:
MOS may not have adopted those out of "copyright" concerns.

More likely, they didn't adopt them because the 6502 didn't have a direct equivalent for any of them. As part of the cost reduction done by Chuck Peddle and company, instructions were removed that could be synthesized with short sequences of other instructions.

I personally have never had a need for instruction aliases. To me, it's just more junk to learn. :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by BigDumbDinosaur »

Getting back on topic, a macro I use a lot in 65C816 programming is one that generates a stack frame when given a list of parameters:

Code: Select all

;	generate stack frame from words...
;
pushparm .macro ...            ;accepts an arbitrary number of parameters
         .if %0                ;if at least 1 parameter...
.i           .set 0            ;initialize parameter index
             .rept %0          ;repeat for number of parameters
.i               .= .i+1
                 pea #%.i      ;push parameter as a word
             .endr             ;end of repeated block
             pea #.i           ;push number of words in frame
         .else
             .error "error: macro syntax: "+%0$+" param1[,param2[,param3]] ..."
         .endif
         .endm

The above is for the Kowalski assembler. The leftmost parameter in the macro invocation will be at the top of the stack frame. The lowest word on the stack, that is, the word at SP+1, will be a count of the total words in the frame, not including the count itself.

The %0$ variable is the macro's name. Should the macro be invoked without any parameters, the message...

  • error: macro syntax: pushparm param1[,param2[,param3]] ...


...will be displayed and assembly will halt.

I've found in 65C816 programming that "long" addresses are better handled as 32-bit quantities instead of 24 bits, especially if pointer arithmetic will be involved. The problem is how to push a 32-bit pointer given a 16- or 24-bit address. In the Kowalski assembler, that's easy. For example, to push two 32-bit pointers, the macro would be invoked as follows:

Code: Select all

         pushparm ptr1 >> 16, ptr1 & $FFFF, ptr2 >> 16, ptr2 & $FFFF

The >> 16 notation is a 16-bit right-shift and & $FFFF is a logical AND that masks bits 16-31.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Gungwald
Posts: 2
Joined: 21 Aug 2021
Location: Columbus, Ohio USA
Contact:

Re: Macro/Function Pseudo Instructions Everyone Should Use?

Post by Gungwald »

Gungwald wrote:
BigEd wrote:
I tried to build, but didn't quite make it. I've contacted the owner of a fork on their Github issue. (Tragically, Andrew passed away earlier this month, so we will need third-party assistance. It would be great to have this project of his available as a runnable release.)
I'm the owner of the fork. I will create a buildable version and a runnable release. Sorry to hear about Andrew. That is a terrible loss.
I have created a release of the dev65 assembler that includes an installable binary. I've made it as easy as possible to install on Linux, Mac, and Windows. I wanted to support my Mac G4 but unfortunately this version requires Java 1.6 or greater. The current version of Java is Java 11. If you have that, you're good. Yes, Java version numbering is stupid. If you're still using Java 8, like so many companies are today, it's time to move on.

Download installer

If you have trouble, open an issue and I'll fix it.
Post Reply