Sunday, October 6, 2024

ALPP 03-0X -- Binary (Base Two) Output on the 6800 with Pseudo-code Mixed in

I decided it was a little early to try to teach you to hand-compile code. 

Go here for binary output on the 6800: https://joels-programming-fun.blogspot.com/2024/10/alpp-03-01-binary-output-6800-left-to-right-framework-by-include.html.

Binary (Base Two) Output
on the 6800
with Pseudo-code Mixed in

(Title Page/Index)

 

Okay, I used 16-bit math as an excuse to show you in some detail three ways to pass parameters at run-time, and now we've worked our way through that on the 68000.

It's getting to be tedious, relying on the debugger for seeing what's going on in the program, isn't it?

So, how about we look at ways to get binary numeric output on the terminal screen?

Binary's easy. All you do is look at the bits and spit them out. Something like this, in an abstract pseudo-language that looks a little like C:

void output0(void)
{
    putchar( '0' );
}


void output1(void)
{
    putchar( '1' );
}

void outbinary_8bit( unsigned int value )
{
    unsigned byte count;
    unsigned localvalue = value;

    for ( count = 8; count > 0; --count )
    {
        unsigned int carry = 0x80 & localvalue;
        localvalue <<= 1;
        if ( carry )
        {
            output1();
        }
        else 
        {
            output0();
        }
    }
}

Let's hand-compile that for the 6800:

* void output0(void)
* {
* Output a 0
OUT0	PSHA
	PSHB
*    putchar( '0' );
	LDAA	#'0
	JSR	OUTCH
	PULB
	PULA
	RTS
* }
*
* void output1(void)
* {
* Output a 1 
OUT1	PSHA
	PSHB
*    putchar( '1' );
	LDAA	#'1
	JSR	OUTCH
	PULB
	PULA
	RTS
* }
*
*
* void outbinary_8bit( unsigned int byte )
* {
* Output the 8-bit binary (base two) number on the stack.
* For consistency, we are passing the byte in a 16-bit word.
OUTB8	LDX	PSP
*    unsigned byte count;
*    unsigned localvalue = value;
	LDAB	1,X
*    for ( count = 8; count > 0; --count )
	LDAA	#8	; 8 bits
*    {
*        unsigned int carry = 0x80 & localvalue;
*        localvalue <<= 1;
OUTB8L	LSRB		; Get the leftmost bit.
*        if ( carry )
	BCS	OUTB81
*        {
*            output1();
OUTB80	BSR	OUT1
*        }
	BRA	OUTB8L
*        else 
*        {
*           output0();
OUTB81	BSR	OUT0
*        }
	DECA
	BHI	OUTB8L	; branch if Carry clear and not Zero
*    }
	INX
	INX
	STX	PSP
* }

That's actually a little cluttered, but you can see the correspondence between the pseudo-C and the assembly language code.

You'll need some setup and tear-down code to make it actually work, and a test frame to call it, but that should work. Let's see if it does.

 

 

.


(Title Page/Index)

 

 

 

 

No comments:

Post a Comment