This program sets up a number of RSX commands which provide you with an in-line assembler facility similar to that found on BBC machines. The program should run on any of the Amstrad CPC range of computers. This method of assembly offers considerable advantages over more traditional approaches of generating machine code routines for use with Basic programs. These usually involve the use of a separate assembler, in Basic or machine code, to generate the routines. These are then either loaded into the Basic program each time it is run, or converted into long lists of Data statements containing strings of apparently meaningless hex values. With this in-line assembler, machine code instructions can be freely interspersed with normal Basic statements. This means that time-saving machine code routines can be easily incorporated into Basic programs, and the fact that they are written in assembler means that they are easily readable and can be altered at any time. Speed of assembly is also very fast, at up to 60 instructions per second! After typing in the program in Listing 1, you should save it to tape or disk and then RUN it. If all is well, the program will set up the necessary machine code in high memory and then automatically save it for you. (If you have made any typing errors in the Data statements, the program will inform you of them. You can then correct the offending line(s) and RUN the program again.) The saved code contains all you need in order to use the assembler. When you subsequently want to use the assembler, just add the following line at the start of your Basic program: MEMORY 39499 : LOAD "asm.bin", 39500 : CALL 39500This will load the assembler into memory and initialise all the RSXs ready for use.The assembler uses 8080 mnemonics throughout, but additional commands are provided to enable all Z80 instructions to be used. All the available mnemonics are listed with the program beside their Z80 equivalents. Note that M, X+n and Y+n are used throughout in place of the Z80's (HL), (IX+n) and (lY+n). In addition, the following special commands are provided: | |ORG, addr | Tells the assembler where in memory to put the generated code. | | |PHASE, addr | Used to asemble code at one address (as specified by the |ORG command) which will later be loaded and run at the address specified with |PHASE. For example, you may wish to load an RSX way up at 40000, but you can't assemble it there directly since it would overwrite the assembler itself. Therefore, you would use something like: MEMORY 29999 |ORG, 30000 |PHASE,40000and then save the assembled code using:SAVE "filename, bin", b ,30000, lengthand later re-load it with:LOAD "filename, bin",40000 | |DEFB or |DB | Each is followed by a list of values (up to 32) which will be placed consecutively into memory as single bytes. | |DEFW or |DW | Each is followed by a list of values (up to 32) which will be placed consecutively into memory as 16-bit words in Z80 byte-reversed format. | | |DEFS,n or |DS,n | Used to reserve a space of n bytes in the code generated. | | | Note that this space is simply skipped by the assembler it is not initialised to zero. | |DEFM or |DM | Followed by a quoted string (6128 only) or the address of a previously initialised string variable, it inserts the specified string into memory. | |DEFC or |DC | As above, except that the very last character of the string is stored with the high bit set. | | |LABEL,@ var or |DEFL,@var or |DL,@var | Used to assign the current assembly address to the specified Basic variable. (The variable must be previously defined and should not be used in any other |LABEL command.) | | |END | Used to signal the end of the assembly. | | |END,@var | As above, but loads the specified variable with the address of the next free byte after the generated code. Thus, it is equivalent to writing |LABEL,@var: |END and, as with |LABEL, the variable must be previously defined. | |DISPLAY or |DISPLAY,1 | This command causes the message ‘Assembling at &nnnn' to appear onscreen. All subsequent commands will update the displayed value as assembly progresses, which provides useful confirmation that the assembly is still proceeding and indicates where the code is being placed. If this display option is still active when an |EWND command is met, then the program will automatically display the start and end addresses of the generated code and its total size in bytes. Note that all displayed values are in hex. This command turns off the above screen display, if active. Note that the |END command does this automatically. | | |DISPLAY,0 | This command turns off the above screen display, if active. Note that the |END command does this automatically. | | | |
The demonstration program shown in Listing 2 illustrates how to use the assembler. The important points to note are as follows: - Only integer variables should be used throughout, hence the DEFINT a-z in Line 40.
- Space should be reserved for the machine code to be generated by setting the top of memory as shown in line 60.
- Lines 100 and 110 must be included in any program since they initialise the necessary register constants for the program to work.
- All labels used in the assembler must first be declared, as in line 120.
- The assembler statements should all be executed twice (lines 180 and 350) to make sure that all forward-referenced labels are assigned the correct address.
- All programs must have an |ORG command and this must be executed before any other command.
- If an |PHASE command is used, it must immediately follow the |ORG command.
- Multiple commands are allowed on a line.
- Comments may be included using the normal Basic ' or REM.
- Conditional assembly is possible using IF . . . THEN statements; or IF . . . THEN . . . ELSE statements for short pieces of code on a single line; or WHILE . . . WEND structures for more substantial amounts of code.
- Limited macro facilities are possible using Basic's GOSUB command, and repeat operations can be assembled using FOR . . . NEXT structures.
It is also possible to use the assembler from the command level without having to construct a program. For instance, try entering the following: MEMORY 29999 A =7|ORG, 30000 |MVI, A,224 |CALL, &BB5A |RET |ENDNow type:CALL 30000and you should see a smiling face appear on the screen! However, this method of entering code is not really recommended, even for very short programs, since it is much too easy to make a mistake. It is far better to write a proper program and save it to tape or disk before assembling and running it.If desired, the names of any of the commands can be altered simply by changing the entries in lines 3000 to 3250 in Listing 1 and then re-running the program. However, ensure that no names are removed or added and that the entries remain in exactly the same order as in the original listing. Also, each name should only contain valid RSX characters such as A to Z. APC
| ★ AMSTRAD CPC ★ DOWNLOAD ★ |
CPCrulez[Content Management System] v8.732-desktop/c Page créée en 305 millisecondes et consultée 393 foisL'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko. |
|
|
|