Overview
This week we will move to the computing environment we will be using for the rest of the course (and beyond), the Altair Z80 with CP/M. Since there is only one meeting day during Thanksgiving week, we'll tack that on to this one.
Friday, November 20th and Tuesday, November 24th
Classwork / Homework / Evaluation
Let's give ourselves the goal of finishing with assembly programming on the on CP/M by Tuesday, November 24th. That will give us two more classes. I'll wait for a message from Chris after class ends on the 24th, and if he gives me the green light, I'll prepare a lesson to switch to C on Tuesday, December 1st.
To get things moving, here are a few simple assembly programs we can assemble
and run. We'll begin with the classic Hello World!
program.
; HELLO.ASM - Print a string to the console
BDOS EQU 0005H ; BDOS entry point
PRTSTR EQU 09H ; BDOS function 9: Print String
ORG 0100H ; CP/M programs always start at 100H
START: LXI D, MSG ; Load address of message into DE
MVI C, PRTSTR ; Load function 9 into C
CALL BDOS ; Call CP/M to print the string
RET ; Return to CP/M prompt (CCP)
MSG: DB 'HELLO FROM THE ALTAIR 8800!$'
END START
Here's one that echos keys and traps ^C to quit.
; ECHO.ASM - Echo keystrokes until Ctrl+C is pressed
BDOS EQU 0005H ; BDOS entry point
CONIN EQU 01H ; BDOS function 1: Console Input
CONOUT EQU 02H ; BDOS function 2: Console Output
CTRLC EQU 03H ; ASCII code for Ctrl+C
ORG 0100H
LOOP: MVI C, CONIN ; Read character into A (also echoes automatically)
CALL BDOS
CPI CTRLC ; Compare A with Ctrl+C
JZ EXIT ; If Ctrl+C, exit to CP/M
; Print brackets around the character to show our program processed it
PUSH PSW ; Save the character in A on the stack
MVI E, '[' ; Load '[' into E
MVI C, CONOUT ; Print '['
CALL BDOS
POP PSW ; Restore the typed character into A
MOV E, A ; Move it to E for printing
MVI C, CONOUT ; Print the character
CALL BDOS
MVI E, ']' ; Load ']' into E
MVI C, CONOUT ; Print ']'
CALL BDOS
JMP LOOP ; Repeat forever
EXIT: JMP 0000H ; Warm boot CP/M (safe exit)
END LOOP
And this one prints the ASCII characters from 'A' to 'Z'.
; ALPHA.ASM - Print A through Z
BDOS EQU 0005H
CONOUT EQU 02H
ORG 0100H
START: MVI B, 'A' ; Starting character
MVI D, 26 ; Loop counter (26 letters)
NEXT: MOV E, B ; Move current letter to E for BDOS
MVI C, CONOUT ; Function 2: Console Output
PUSH B ; Save B and C (BDOS destroys registers!)
PUSH D ; Save D and E
CALL BDOS ; Print character
POP D ; Restore D and E
POP B ; Restore B and C
INR B ; Increment ASCII character ('A' -> 'B')
DCR D ; Decrement loop counter
JNZ NEXT ; Jump back to NEXT if D is not zero
RET ; Return to CP/M
END START
That should be enough to get you going. Have fun!
Wednesday, November 18th
Classwork / Homework / Evaluation
I stated on Monday that my goal was to have you port your postfix calculator to the CP/M environment. This will be a wonderful way for you to take something with which you are deeply familiar and to learn what we want to learn about CP/M and what it provides by seeing this familiar program in the next context.
However, it seems several of you were blocking on Monday due to the restrictions again learning on your school issued laptops. We'll need to address that challenge before moving on with this project, and I have a few idea about how to approach that, which we'll discuss at the beginning of class.
Take a look at
Appendix C: Altair Z80 Setup and notice the file ASM.COM.
See if you can use it to assembly your program.
Monday, November 16th
Classwork
Our textbook has been updated with an Appendix C: Altair Z80 Setup describing how to setup our new computing environment. We will start today by going through that.
After setting up our new environment, we need to begin learning how to use it. We'll want two new skills before we can begin writing C programs:
- Basic usage of the CP/M Console Command Processor
- Ability to use the WordMaster text editor included with our new computing environment to edit text files
Appendix D: CP/M Cheat Sheet and Appendix E: WordMaster Cheat Sheet should be all we need to accomplish these two learning goals.
Homework
Using the resources provided, familiarize yourself with both the basic CP/M commands and the WordMaster editor.