Copy Link
Add to Bookmark
Report
Efficient Message Printing
Assembler coding - Lesson 2
Printing messages on the screen
OK here we will again print some text to the screen. Only this time we'll see how to do it using better methods.
Right then, lets assume we want to print out somewhere on the screen, lets say the middle, the following text:
HELLO FROM ROB & BJOERN
We could use the method from LESSON 1, remember JSR $FFD2. But that method sucks.
Instead lets use the SCREEN MEMORY MAP. You can view this map in the C64 programmers reference guide.
OK, here's one way of doing this task:
10 LDA #72 - (The value for H)
20 STA 1554 - (Print at location 1554)
30 LDA #69 - (The value for E)
40 STA 1555 - (Print at location 1555)
40 LDA #76 - (The value for L)
50 STA 1556 - (Print at location 1556)
etc
As you can see, this method is pretty tedious too. Especially if you have a long message to write. So here's a better way, with an explanation after the listing:
10 ORG 8192
20 LDX #00
30 LDA #23
40 STA 53272
50 LOOP LDA MESS,X
60 CMP #93
70 BEQ DONE
80 STA 1555,x
90 INX
100 JMP LOOP
110 DONE RTS
120 MESS DFM 'HELLO FROM ROB & BJOERN]'
Ok here's the explanation for the code above:
- 10 ORG 8192 - Set place in memory to assemble code at - (SYS 8192 to run)
- 20 LDX #00 - This sets the X register to the value zero
- 30 LDA #23 - Give accumulator the value 23 decimal
- 40 STA 53272 - Store accumulator at this address to make characters LOWERCASE
- 50 LOOP LDA MESS,X - Ok here's how this bit works. This line loads the value pointed to by the address location MESS plus the value of the X register. Initially the X register = 0, so the first bit of data loaded into the accumulator is the first letter of the message data, i.e. H. But when the X Register = 1, then MESS + 1 will load the next value, i.e. E. and so on.
- 60 CMP #93 - This line checks to see if the data in the accumulator = 93. This is the value for the ] at the end of the message. Using this we can check to see if we have finished printing all the data.
- 70 BEQ DONE - Line 60 actually performed a little maths that you didn't know about. This line checks the result of the maths, and if the result = 0 then this line makes the program branch to the line labelled DONE. If the maths does not = 0 then the program continues to line 80.
- 80 STA 1555,X - Using X register again, we can store the message on the screen. This is opposite to the LDA,X on line 50. Here we store the value at 1555+X. So H gets stored at location 1555, E gets stored at 1556 and so on.
- 90 INX - This line increments the X Register by 1, so if it was 0, it is now 1.
- 100 JMP LOOP - This just jumps back to the line labelled LOOP.
- 110 DONE RTS - Last character fetched, so exit the program.
- 120 MESS DFM 'HELLO FROM ROB & BJOERN]' - This is just the message, notice the ] at the end.
Remember that you can view the instruction set and meanings in the Programmers Reference Guide.