|
Converting BASIC to assembler |
|
It is always seen as a fairly major thing to port BASIC programs to assembler; while it is a rather deep and irksome thing to do, it must be remembered that the operating system is more than willing to help out.
Here are some examples...
SWI "OS_ReadC"
OS_Byte 129 to check for a specific key or to read a key within a
given time.
; read the input
ADR R0, buffer
MOV R1, #128 ; max. line length is 128 characters
MOV R2, #32 ; min. ascii allowed is space (32)
MOV R3, #126 ; max. ascii allowed is 126
SWI "OS_ReadLine"
; echo the string (optional)
ADR R3, buffer
.echo_loop
LDRB R0, [R3], #1 ; BASIC's INPUT does an echo of the
SWI "OS_WriteC" ; data entered, but you may prefer
CMP R0, #13 ; not to do this. Up to you.
BNE echo_loop
SWI "OS_NewLine"
MOV PC, R14 ; now return to caller
.buffer
EQUS STRING$(128, CHR$(0))
SWI 256+32.
VDU 31, x, y, like:
MOV R1, #100 ; X
MOV R2, #200 ; Y
; do it
SWI 256 + 31 ; VDU 31
MOV R0, R1
SWI "OS_WriteC" ; output X
MOV R0, R2
SWI "OS_WriteC" ; output Y
That simply scratches the surface. You need to stop thinking of 'integers' and 'strings' and instead think of them as units. For example, a string is simply a sequence of bytes starting at a given location and continuing until a certain condition (such as a terminator byte or length count) is met.