What do the operands and symbols mean? Anyone?

Let's talk about anything related to the 6502 microprocessor.
Jmstein7
Posts: 379
Joined: 30 May 2021

Re: What do the operands and symbols mean? Anyone?

Post by Jmstein7 »

Got another one. I'm trying to port a program for the 65c816, and I encountered this bit of code:

Code: Select all

;===============================================================================
; D - Disassemble Memory
;-------------------------------------------------------------------------------

                cmp     #'D'                    ; Memory display?
                bne     NotDisassemble

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError

                php
                pla
                sta     FLAGS
My assembler doesn't like the "$+5". I think the code is trying to advance the PC five addresses forward, if the carry flag is cleared,in which case I think I could do:

Code: Select all

BCC *+5
Is this correct, anybody? I've not encountered "$+" before.

Jon
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: What do the operands and symbols mean? Anyone?

Post by drogon »

Jmstein7 wrote:
Got another one. I'm trying to port a program for the 65c816, and I encountered this bit of code:

Code: Select all

;===============================================================================
; D - Disassemble Memory
;-------------------------------------------------------------------------------

                cmp     #'D'                    ; Memory display?
                bne     NotDisassemble

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     $+5
                jmp     ShowError

                php
                pla
                sta     FLAGS
My assembler doesn't like the "$+5". I think the code is trying to advance the PC five addresses forward, if the carry flag is cleared,in which case I think I could do:

Code: Select all

BCC *+5
Is this correct, anybody? I've not encountered "$+" before.
Does it work with *+5?

To remove confusion, I'd be inclined to replace them with labels though.

so:

Code: Select all

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     startOk
                jmp     ShowError
startOK:
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     endOK
                jmp     ShowError
endOK:
and so on.

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Jmstein7
Posts: 379
Joined: 30 May 2021

Re: What do the operands and symbols mean? Anyone?

Post by Jmstein7 »

drogon wrote:
Does it work with *+5?

To remove confusion, I'd be inclined to replace them with labels though.

so:

Code: Select all

                ldx     #ADDR_S                 ; Parse start address
                jsr     GetAddr
                bcc     startOk
                jmp     ShowError
startOK:
                ldx     #ADDR_E                 ; Parse end address
                jsr     GetAddr
                bcc     endOK
                jmp     ShowError
endOK:
and so on.

-Gordon
Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:

Code: Select all

                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro
It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!
John West
Posts: 383
Joined: 03 Sep 2002

Re: What do the operands and symbols mean? Anyone?

Post by John West »

Jmstein7 wrote:
.dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
It's taking three characters and packing them into a 16 bit word. P is given the top 6 bits, Q is given the next 5, and R the lowest 5. @ is encoded as 0, A as 1, B as 2, and so on. Unwrapping it: P-'@' subtracts the code for @ from P, giving 0, 1, 2, ... Then it shifts that up 5 bits. Q-'@' does the same to Q, these two result get ORed together by the |, then the result of that is shifted five bits up. Finally the value from R gets ORed in.
Your assembler obviously doesn't like this expression as it is, but I couldn't guess exactly what it's complaining about. It's not the most helpful error message. I'd start by stripping the expression down the the bare minimum and gradually adding bits back until it fails. So

Code: Select all

    .dword P
    .dword P-'@'
    .dword (P-'@')<<5
and so on. Knowing which bit of syntax it's unhappy about will help a lot in trying to write something that it does like.
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: What do the operands and symbols mean? Anyone?

Post by drogon »

Jmstein7 wrote:

Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:

Code: Select all

                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro
It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!
It's compressing 3 characters into 2 bytes. Woz did this in his disassembler and one-line assembler. If this is failing for you, then your assembler doesn't support those actions, so short of changing assembler, you might need to work it out the hard way.

Although checking now - .dword - that might imply a double word and maybe 4 bytes, so compressing 3 characters into 4 bytes is odd, so I guess it really means a 16-bit word. I checked it in ca65 and it seems OK, but the syntax is different, so:

Code: Select all

.macro  MNEM    P,Q,R
        .word   ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
.endmacro

        MNEM    'L','D','A'
works with the output:

Code: Select all

00C006  1  81 30                MNEM    'L','D','A'
So, L,D,A -> $81, $30.

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
Jmstein7
Posts: 379
Joined: 30 May 2021

Re: What do the operands and symbols mean? Anyone?

Post by Jmstein7 »

No matter how I try, it just won’t work - word, double word, bytes, etc.

This is driving me bananas.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: What do the operands and symbols mean? Anyone?

Post by barrym95838 »

Can you link us to your assembler's documentation, if any? There should be a way to get the job done without hand-translating and hard-coding the hex data.
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
Jmstein7
Posts: 379
Joined: 30 May 2021

Re: What do the operands and symbols mean? Anyone?

Post by Jmstein7 »

barrym95838 wrote:
Can you link us to your assembler's documentation, if any? There should be a way to get the job done without hand-translating and hard-coding the hex data.
Mike,

Here it is: https://enginedesigns.net/download/retroassembler.html

Thanks!

Jon
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: What do the operands and symbols mean? Anyone?

Post by BigDumbDinosaur »

Jmstein7 wrote:
The other item I'm having trouble with is this:

Code: Select all

                .macro      MNEM(P,Q,R)
                .dword      ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
                .endmacro
It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')

Argh!

I tried that in the Kowalski assembler, which uses curly brackets instead of parentheses for determining evaluation precedence. It works as expected.

However, .DWORD in the retroassembler causes the generation of a 32-bit, little-endian value. Replace the .DWORD in the above expression with .WORD to produce the 16-bit, little-endian value expected by the mnemonic parser.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Jmstein7
Posts: 379
Joined: 30 May 2021

Re: What do the operands and symbols mean? Anyone?

Post by Jmstein7 »

BigDumbDinosaur wrote:

I tried that in the Kowalski assembler, which uses curly brackets instead of parentheses for determining evaluation precedence. It works as expected.

However, .DWORD in the retroassembler causes the generation of a 32-bit, little-endian value. Replace the .DWORD in the above expression with .WORD to produce the 16-bit, little-endian value expected by the mnemonic parser.
It didn't work with .word, but it did work with .textz . Weird.
teamtempest
Posts: 443
Joined: 08 Nov 2009
Location: Minnesota
Contact:

Re: What do the operands and symbols mean? Anyone?

Post by teamtempest »

Quote:
Great idea! There are thousands of lines of code, so it would be hard to debug. The other item I'm having trouble with is this:
Code:
.macro MNEM(P,Q,R)
.dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
.endmacro


It is telling me that this is an "Unsupported format of parameters" with regards to .dword ((((P-'@')<<5)|(Q-'@'))<<5)|(R-'@')
It's telling you something is wrong with 'P', 'Q' , and/or 'R'. The expression itself is not a problem as the documentation says all the operators used are supported (same as C syntax).

Perhaps the problem is that P, Q, and R are not interpreted as characters but as labels? Subtracting a character from a label won't work. Are you writing

Code: Select all

MNEM(L, D, A)
instead of

Code: Select all

MNEM('L', 'D', 'A')
by any chance?

Also '.dword' generates a 32-bit value. Better is '.word' to generate a 16-bit one.
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: What do the operands and symbols mean? Anyone?

Post by BigDumbDinosaur »

teamtempest wrote:
It's telling you something is wrong with 'P', 'Q' , and/or 'R'...Perhaps the problem is that P, Q, and R are not interpreted as characters but as labels? Subtracting a character from a label won't work. Are you writing

Code: Select all

MNEM(L, D, A)

That would definitely upset the apple cart, depending on if any of those are even defined and if so, what values they hold.

Quote:
Also '.dword' generates a 32-bit value. Better is '.word' to generate a 16-bit one.

As I noted in my post... :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
Post Reply