QASM - A BRIDGE TO MACHINE CODE This program is aimed at two types of customers. The first is the one who feels that he has mastered the Basic language and wishes to turn his attention to machine code, but is not quite sure how to go about it. The second is the experienced machine code hacker. For the second category, QASM is essentially a collection of sub-routines plus a list of equates. The idea is that the equates are loaded into the editor and called as necessary. At run time QASM itself is loaded in addition to whatever program has been assembled and, of course, the equates call QASM. For the customer who is just starting to get his feet wet in machine code programming, QASM will prove to be a godsend. The difficulty that a lot of people have is trying to get their mind away from the ease and almost English like syntax of Basic and into the idea of using registers and various other functions for manipulating the data. Although this catalogue is not intended as a tutorial, people may be interested to know that a very good way of bridging the gap between Basic, in particular, but no doubt other high level languages as well, is to buy and use a programmable calculator. These are not quite as popular as they used to be because we now have pocket computers, but you can still buy them. We are more conversant with the Texas Instrument SR series but these remarks apply equally well to the Hewlett Packard. With these calculators one is forced to use registers rather than variable names. Also it introduces one to the concept of indirect addressing in a moderately painless fashion. Anyway, this is all by the by, particularly in the context of the description of this program, because QASM will, to a large extent, save you the cost of a programmable calculator. In other words, QASM forms a bridge between Basic and machine code. Those readers who use assemblers may skip the next paragraph or two because it is necessary for us to explain some of the mechanics before those customers unacquainted with assembly can understand what QASM is all about. In a Basic program, if one wants to call a subroutine then one uses the command GOSUB and follows it with a line number. If one wishes to branch or jump to another section of the program without a return, then one uses the statement GOTO. One of the big differences of assembly language (incidentally, 'assembly language' and 'machine code' or 'machine language' are all used pretty well interchangeably) is that one does not define a line number to which a jump, conditional or otherwise, is to be made. One defines it by giving it what is called a label. Usually this is a mnemonic of the function of the subroutine. If one has, for instance, a subroutine that performs a SIN function on a number in a particular register, then one might well call the subroutine SIN. Furthermore, it is often very useful to make a mnemonic description label equal to something other than a subroutine. Take, for instance, the situation where a program is frequently calling something in ROM. For example, in cassette work the better known ROM routines are clustered around the 200H area of ROM. A call to 212H turns on the motor of the cassette on the Model I, a call to 284H writes the tape leader, a call to 264H writes one byte from the A register and so on. It is perfectly possible in a program if one wants to turn on the cassette motor simply to assemble the instruction CALL212H. However, if at the beginning of the program one has made 212H equal to the label MOTOR then obviously the program is going to be much more readable, in that one can CALL MOTOR. Hence, most people use the Equate command in the assembler to set up labels, both within and without the limits of the program. QASM consists of two separate sections of code. The first is in what is called source form and it may be loaded into an assembler. It consists of a large number of equate statements. There are about 110 or so in all. These are loaded into the Editor/Assembler that the customer is using before he starts to write his program. The program is then written using as many of the equates as the author wishes and then assembled in the normal way. When the thus written program comes to be used, the other section of QASM is loaded in addition to the home written program. The address of the equates tie up with the addresses of QASM and, as QASM and the program are both in memory, the machine will consider the two to be one. In other words, that QASM and the custom written program are one program. This is an extremely fast way of writing code because over 100 subroutines have already been written for you. This no doubt why Mr. Woodruff (who also wrote Horolog, Astrolog and Astronomical Calender) used the acronym for 'Quick ASeMbly'. More important than speed of assembly however, those people who are just starting to write assembly have not only got a large quantity of code already written for them, but it has been labelled in such a way that it is meaningful to a person familiar with Basic. Thus, pretty well all of the mathematical functions are supported as is the random function and even the FOR NEXT loops. Let us illustrate the use of QASM with the random number. A normal basic statement would be A = RND(20). If you are not familiar with machine code you might scratch your head for quite a while trying to find a way of converting this Basic statement, which you know so well, into the equivalent assembly code. With QASM, it is only necessary to assemble four lines as follows: LD HL,20 --- --- CALL RND LD HL,XA CALL FPV The first line stores the number 20 into the HL register, the second line calls the subroutine in QASM, entitled RND, the third loads the address of a pseudo variable XA and the final line calls a subroutine in QASM which puts the random number into the pseudo variable. It will be seen, therefore, that the task of producing a random variable in machine language has been made rather simple because of the help given by QASM. QASM operates in single precision, it does not support double precision. As we have seen, QASM supports what we have termed pseudo variables, and you may perform pretty well any mathematical function upon them. SIN, COS, TAN, ATN, SQR, SGN FIX, INT, ABS, LOG and EXP, for instance, all carry out the same functions as their Basic equivalent. We have already mentioned that Random is supported, so also are three comparisons, namely compare equally, compare larger or compare smaller. FOR NEXT loops on n, GOTO, GOSUBs and so on are all available. There are also special routines for accepting a number from the keyboard and printing. Strings are also supported. For instance, the common Basic statement PRINT x A$ in QASM language becomes: LD HL,YA --- --- CALL PTLIN The first line stores a pointer in the register HL,YA, of course, is the string variable and the call simply prints it out. String manipulation is also supported, such as Basic statements LEN and ASC. The Basic statement READ is supported in a sort of quasi way. Arrays are supported. In the field of graphics, SET, RESET and POINT in QASM are the same as the Basic equivalents. As we have said, we do not have the space to list all of the calls in QASM, but the above should give a pretty good idea of the extent of this extremely useful utility. QASM is supplied with a printout of a demonstration program which uses its functions. This is fully commented and would be very useful to people who want to see how QASM is used. Although irrelevant to its function as a demonstration program, the program does in fact calculate the distance in nautical miles on great circle routes.