6801 assembly: subroutine analysis

Thread Starter

metermannd

Joined Oct 25, 2020
343
Edit: I'd originally asked what the function of the routine below was.
It was determined that this code takes a BCD number and converts it to hexadecimal.

I originally had generic mnemonics on all the addresses, but they have now been named properly
(loop counter, address output, and 2 scratchpad bytes).

Code:
func01:
    CLC   
    CLR    temp6
    CLR    addrL
    CLR    addrM
    CLR    addrH
    LDA A    #$07
    STA A    loopCount
    LDX     #$:0C27    // readout
func01_1:
    LDA A    addrM
    LDA B    addrL
    ADD B    $:00,X
    STA B    addrL
    BCC     func01_2
    ADD A    #$01
    STA A    temp6
    STA A    addrM
    BCC     func01_2
    LDA A    addrH
    ADD A    #$01
    STA A    addrH
    LDA A    temp6
func01_2:
    DEC     loopCount
    BNE     func01_5
    RTS   
func01_5:
    ASL D   
    STA B    addrL
    STA A    temp6
    STA A    addrM
    ROL     addrH
    LDA A    addrH
    STA A    temp7
    LDA A    temp6
    ASL D   
    ROL     temp7
    ASL D   
    ROL     temp7
    ADD B    addrL
    STA B    addrL
    ADC A    addrM
    STA A    addrM
    BCC     func01_6
    INC     addrH
func01_6:
    LDA A    temp7
    ADD A    addrH
    STA A    addrH
    DEX   
    BRA     func01_1
 
Last edited:

MrChips

Joined Oct 2, 2009
30,824
There are 6800/6811 emulators available.
You can try one of these. This will allow you to step through the code and see what the code does.
 

Thread Starter

metermannd

Joined Oct 25, 2020
343
I can't find any such apps that will run natively under modern versions of macOS, and I made the mistake of 'upgrading' to a Mac with the M1 processor, which is unable to run x86 code (so I can't run Windows either).
I'm at the point where I think I'm just going to abandon this project completely.
 

MrChips

Joined Oct 2, 2009
30,824
I can't find any such apps that will run natively under modern versions of macOS, and I made the mistake of 'upgrading' to a Mac with the M1 processor, which is unable to run x86 code (so I can't run Windows either).
I'm at the point where I think I'm just going to abandon this project completely.
It may be easier to get a low cost PC to run MS Win.
 

Thread Starter

metermannd

Joined Oct 25, 2020
343
Hmmm. set it in a corner and just remote into it. Hmmm....
I do have that W7 license / DVD I can no longer use for the virtual environment.

Incidentally, I had a flash of insight regarding the bit of code.
Is it possible that this piece of code takes a 7-digit BCD number and converts it into a 3-byte hexadecimal number?
 

MrChips

Joined Oct 2, 2009
30,824
I ran the code into a 68HC11 simulator.
It converts a 7-digit BCD number into 24-bit unsigned integer, i.e. 3-byte result (straight binary).

(The first byte at $0C20 is ignored.)

Max input is 9,999,999
Result is $98 96 7F

All data is stored in little endian mode, i.e. least significant byte first.
 

Thread Starter

metermannd

Joined Oct 25, 2020
343
I now have a reman'd PC on the way, and will set up remote desktop to connect to Windows when needed, as there are other apps that would be nice to have at hand once again.
Being able to tag the three output bytes from this routine with their function helped further clarify other parts of the code, and now it's just
that interrupt code that I still need to get my mind around.
 
Last edited:
Many years ago I was using MC6801/ 6803 and later on Hitachi 6303 which was quite popular and I have some equipment with those processors. And I did program some years using assembler language. If you need more analysis of binary code I could do it for you but the purpose of code would be helpful. <snip>

Moderator edit: email address removed to prevent spam.
 

Thread Starter

metermannd

Joined Oct 25, 2020
343
Thought I'd give this a BIG bump after fixing the mnemonics and doing some code cleanup.

Would like some thoughts on how to rearrange it into a proper loop - in other words, getting rid of the jump down to func01_5 and then back up... I think that's just poor coding. Once I can see how to do so, I can get rid of that silly loop counter in favor of using CPX as should have been done!
 

MrChips

Joined Oct 2, 2009
30,824
Here is what you need.

1) multiply 24-bit unsigned integer by 10. The algorithm is R = (4xR + R) x 2

2) add single digit to 24-bit unsigned integer

Do (1) and (2) seven times.
 
Top