Have you ever wanted to put a reverse character in a string but you had no way of doing it? Here is a simple answer, a small machine language program that will reverse a character for you:
Decimal Mnemonic
221,42,8,64 LD IX (nn)
33,70,64 LD HL, nn
35 INC HL
126 LD A (HL)
221,190,0 CP (IX+d)
200 RET cc
254,27 CP n
194,50,64 JP cc, nn
35 INC HL
126 LD A (HL)
198,128 ADD A, n
119 LD (HL) A
195,50,64 JP nn
How It Works
The first line loads the IX register with the memory location of the end of the Basic program, pointed by VARS, then the HL register is loaded, LD HL, nn, with the end of the machine language program. The HL register is then incremented in the line INC HL. In the next line the A register is loaded with the memory contents pointed to by HL. The A register is then compared to the memory location pointed by the IX register. If they are equal, the program returns to Basic. The two will only be equal if it is at the end of the Basic program. The A register is then compared, CP n, with 27, the character number of “.”. If they are not equal, then the program jumps up to INC HL and repeats the cycle. If they are equal, then HL is incremented and the A register is loaded with the memory contents pointed by HL. Then 128 is added, ADD A, n, to A to get the reverse of the character. It is then loaded back into the memory location pointed by HL. Finally the program jumps back to the first INC HL and continues until the end of the Basic program.
Writing the Program
Type the following:
REM 12345678901234567890123456
100 FOR X=16427 TO 16452
110 PRINT X,,
120 INPUT A
130 IF PEEK(16421)<2 THEN CLS
140 POKE X,A
150 PRINT PEEK(X)
160 NEXT X
Then type in:
10 REM THEN THEN THEN THEN ...
Continue typing THEN until line 1 disappears, then enter:
10 REM DO NOT GO UP
RUN and enter the following values:
16427 221 16428 42 16429 8 16430 64 16431 33 16432 70 16433 64 16434 35 16435 126 16436 221 16437 190 16438 0 16439 200 16440 254 16441 27 16442 194 16443 50 16444 64 16445 35 16446 126 16447 198 16448 128 16449 119 16450 195 16451 50 16452 64
DO NOT PRESS LIST OR HOME. THE PROGRAM WILL BE LOST IF SHOWN.
Delete lines 100-160; then save the program.
To Operate:
Before writing your own program, load this one. Whenever you need the reverse of a character, insert a “.” before the character to be reversed. Then enter GOTO USR(16427). More than one character can be done at a time.
If you wish to use a different character than “.”, POKE 16641, (the character number of your choice).
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.