Spectrum Assembler Chris Lam makes Z-80 Op-code translation easy. This program assembles Z-80 machine code. All Z-80 mnemo- nics can be entered except those after CB, ED or those that include index registers. The program takes the mnemonics which start at line 2000 and converts them to three characters. This is compared against each string from the data at lines 1800 to 1805. The number of strings it had to read off against before finding a match is the Z-80 Op-code for that mnemonic. Take a look at lines 1820 and 1830. Line 1820 contains all the commands which you can enter. Note that all the RST commands are in decimal. Line 1830 are all the registers you can enter. "NN", "N", "(NN)", and "DS" are there solely to help the computer. All your Z-80 mnemonics must start at line 2000. Each line after that must be incremented by one. See line 1004: the mnemonics must be in quotes and entered as a DATA statement. Only one mnemonic a line is permitted. Therefore type this in: 2000 DATA "LD BC,65535" 2001 DATA "RET" and Run the program. It will ask you how many lines of mnemonics there are. In this case, type in 2. Wait a few seconds and a message "Out of DATA" should appear. These 4 bytes of code have been entered into the memory starting at the address 30000. This can easily be changed to any address at line 1001. Run 3000 and you should get 1, 255, 255, 201. Now if you have enough confidence, type PRINT USR 30000 and you should get 65535. There are however some very important points on how you must enter your machine code program. * There must be no spaces between the 1st quote and the 1st letter of the mnemonic. * There must be only one space between the command and the next part, register or number. For example, "LD (65535),a" is allowed while "LD (65535),a" is not. The same applies to the first register or number and second register or number, but it may be a comma, for example "LD A,B" is OK and "LD A B" is OK. See line 1025. * There should be no spaces at the end. * Enter mnemonics for Op-codes: 211 and 219 without the brackets. * You can have negative displacements. For example, "DJNZ -3" is the same as "DJNZ 253" and both are allowed. Do not forget that "JR 0" jumps to the following byte. As mentioned before, mnemonics that have CB, ED or IX or IY, must be written in hexadecimal prefixed by a hash. There- fore you can write: 2000 DATA "#ED48FF": REM LD BC,(65535) See line 1008. Type in this demonstration program. 2000 DATA "LD HL,0" 2001 DATA "LD BC,100" 2002 DATA "ADD HL BC" 2003 DATA "DEC BC" 2004 DATA "JR NZ -4" 2005 DATA "PUSH HL" 2006 DATA "POP BC" 2007 DATA "RET" This could easily be shorter but is lengthened to show how well this assembler can handle the mnemonics. Run the program and type in 7 to the prompt - despite the fact it has eight lines - and ENTER. It takes the computer two to five seconds to assemble one line of mnemonic, so this will take 20 to 30 seconds. Finally it should display "Loop Finished" (see line 1002 and 1004). Now if you are still doubtful, Run 3000 and check it. Then enter PRINT USR 30000 and the reply should be 5050. For those who haven't a clue why this is printed, the machine code program calculates the total of all the numbers from 1 to 100 added together. [Except that it doesn't, and won't give that answer. The bug is not in the assembler, but in the demonstration machine code. Finding it is left as an exercise for the reader.] Now type in CLEAR 30000 [Make that 29999, unless you really do want to put the top of your stack bang on top of the first byte of your code...] and follow it with NEW. Again type PRINT USR 30000 and you should get 5050 again. So now you have a machine-code program, safe above RAMtop.