Page 4 of 4

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

Posted: Thu Oct 07, 2021 2:08 pm
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

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

Posted: Thu Oct 07, 2021 2:39 pm
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

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

Posted: Thu Oct 07, 2021 3:09 pm
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!

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

Posted: Thu Oct 07, 2021 3:19 pm
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.

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

Posted: Thu Oct 07, 2021 3:21 pm
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

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

Posted: Thu Oct 07, 2021 4:32 pm
by Jmstein7
No matter how I try, it just won’t work - word, double word, bytes, etc.

This is driving me bananas.

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

Posted: Thu Oct 07, 2021 7:26 pm
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.

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

Posted: Thu Oct 07, 2021 7:38 pm
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

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

Posted: Sun Oct 10, 2021 2:25 am
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.

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

Posted: Mon Oct 11, 2021 1:28 pm
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.

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

Posted: Mon Oct 11, 2021 3:02 pm
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.

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

Posted: Mon Oct 11, 2021 7:44 pm
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