In Tom Pittman’s book, “A Short Course in Programming“, he introduced the 64 OUT4 instruction in chapter 3 with little explanation other than saying that OUT 4 would output the next byte in memory to the hex display. This is fine and dandy of course but only if P=X. I glossed over the P=X part the first time I read chapter 3 however so when he re-introduced OUT 4 in chapter 4, I found myself a bit confused. In program 4.2, he tries to make sense of this concept. I am going to take the liberty of recommenting the code to try to make even more sense of it and drive this concept home:
0000 90 GHI 0 .. set D=R0(hi byte), R0=0 after the computer resets 0001 B8 PHI 8 set high byte of R8 to value of D which is zero 0002 80 GLO 0 set D=R0(lo byte), this could JUST as easily be 90 0003 A8 PLO 8 set low byte of R8 to value of D (again, zero) 0004 3F04 WOW: BN4 * .. WAIT FOR "I" (This is a good description) 0006 E8 SEX 8 set X register to point at R8 0007 64 OUT 4 .. OUTPUT TO DISPLAY (see more down below) 0008 C4 NOP .. this byte gets ran so it is critical 0009 3709 B4 * wait for you to take your finger off "I" 000B 3004 BR WOW .. REPEAT (start at the wait for "I" statement)
This program as written sends every byte in memory out to the hex display starting at location 0003 in memory. If you want to start at the beginning of the memory, change 0002 to 90. This will make sure that R8 is completely zero’d out when you start your count. One more observation I have is that location 0008 DOES get executed. If you want to make a slightly more confusing program but save a byte of memory, you can omit the c4 instruction at the location. Just make sure you change the next branch command to 3708 so it jumps to the correct location. You can FURTHER save another byte of memory if you omit the 80 GLO command. Once you’ve GHI’d, you have your D(accumulator) set to zero so why not just PHI and PLO after that without GLOing?
Now for the big explanation. Obviously the meat of the program happens when X gets pointed at R8. That tells the OUT4 instruction to output whatever memory location that R8 is pointing at to the hex display. Usually OUT4 looks at R0 for it’s next byte to display. It also increments whichever register it’s looking at. This is why the next byte after 64 usually is skipped and not executed. Hopefully this makes perfect sense to you by now. Also, there is nothing special about R8. Tom just arbitrarily chose R8 out of the stack. Here is my modified version of Program 4.2 that is smaller, starts at an earlier memory location and uses R2 as the display byte pointer(if that is the proper term…):
0000 90 GHI 0 .. set D=R0(hi byte), R0=0 after the computer resets 0001 B2 PHI 8 set high byte of R2 to value of D which is zero 0002 A2 PLO 8 set low byte of R2 to value of D (again, zero) 0003 3F03 WOW: BN4 * .. WAIT FOR "I" (This is a good description) 0005 E2 SEX 8 set X register to point at R2 0006 64 OUT 4 .. display contents of memory location pointed to by X 0007 3707 B4 * wait for you to take your finger off "I" 000B 3003 BR WOW .. REPEAT (start at the wait for "I" statement)
If you like the content on this site, please support it by using this link to order from Amazon. You know you were going to go there and buy stuff anyhow so why not help me pay the hosting bill.