Hello World program and questions about 2SIO output ready?

General discussions related to the Altair 8800 Clone

Hello World program and questions about 2SIO output ready?

Postby wearwolf » April 26th, 2021, 11:26 am

I've been working through a bunch of test programs to learn more about the Altair 8800 and the 8080 instruction set. I was working on one program to print a null-terminated string when I realized it could be turned into a hello world example. That's where you are supposed to start with any new programming environment right? So here's my take on a Hello World program for the Altair 8800.

This was all hand assembled to the listing may not be properly formatted

Code: Select all
0000                    ORG 0
0000   3E 03            MVI A, 03H   ;Rest 2SIO port
0002   D3 10            OUT 10H   
0004   3E 15            MVI A, 15H   ;Set 2SIO port to 8n1
0006   D3 10            OUT 10H
0008   21 FE 00         LXI H, MSG   ;Load message address
000B   DB 10   CHECK:   IN 10H      ;Check 2SIO output ready
000D   E6 02            ANI 02H
000F   CA 0B 00         JZ CHECK
0012   7E               MOV A, M   ;Load character
0013   FE 00            CPI 00H      ;Check if null found
0015   CA 1E 00         JZ END
0018   D3 11            OUT 11H      ;Ouput character
001A   23               INX H      ;Move to next character
001B   C3 0B 00         JMP CHECK
001E   76      END:     HLT

00FE   48 65 6C 6C      MSG:   Hell
0102   6F 2C 20 77            o, W
0106   6F 72 6C 64            orld
010A   21 0D 0A 00            !\r\n\0


I put the message at 00FE because I wanted it to go over the 1-byte address boundary to make sure it was incrementing the address correctly. Before I found the INX instruction I was thinking I was going to need to do a multi-byte add so I wanted to make sure that worked correctly when crossing that boundary.

Now my question is about this loop.

Code: Select all
CHECK:   IN 10H
         ANI 02H
         JZ CHECK


During an earlier test I was printing a CR and a LF character right after each other and it seemed like sometimes it worked and sometimes output would get missed/muddled. So I added this loop to check that the Transmit Data Register Empty flag is set before outputting a value.

My questions are
1. Is there a better way to check if output is ready? (I figure this has been done enough that people have likely found the best way to do it)
2. Are there any guidelines on when the output ready check is needed?
wearwolf
 
Posts: 4
Joined: April 11th, 2021, 2:41 pm

Re: Hello World program and questions about 2SIO output read

Postby TronDD » April 26th, 2021, 4:41 pm

There are smarter people here than I, but that's basically how to do the check. You could also RRC twice and JNC. Not sure the time difference between two RRC instructions and one ANI.

You should always do the check. The CPU is much faster than a 9600 baud UART.

Fun exercise. Put a counter in the loop and see how many times it has to check between sending 2 characters.
TronDD
 
Posts: 30
Joined: November 20th, 2018, 8:51 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 2 guests

cron