08-24-2011, 07:48 PM
oblo Wrote:I know it's a bit odd to ask this, because the compiler doesn't ask us to learn ASM but...
I'm starting to learn some ASM and besides read some books, I'm trying to get some examples from <!-- m --><a class="postlink" href="http://stu.pido.us/wiki/retrogames:index">http://stu.pido.us/wiki/retrogames:index</a><!-- m --> and <!-- m --><a class="postlink" href="http://members.fortunecity.com/jonathan6/egghead/id2.html">http://members.fortunecity.com/jonathan ... d/id2.html</a><!-- m -->, but every piece of code I try to compile between ASM and END ASM, end with a compiler error, for instance:
Actually, since I started playing with the compiler, I've learned a pile of assembly - up to doing some quite complex things (have a look at the library section of the wiki; I've put quite a few assembly routines in there). What you have to remember is that this is designed to compile code, so you are better off wrapping it in ZX basic, such that it's called from there. Also, different assemblers (or in this case, compilers) have their own little foibles.
oblo Wrote:Code:ASM
ld a,2 ; upper screen
call 5633 ; open channel
loop ld de,string ; address of string
ld bc,eostr-string ; length of string to print
call 8252 ; print our string
jp loop ; repeat until screen is full
string defb '(your name) is cool'
eostr equ $
END ASM
...ends with "temp.bor:11: Error: illegal preprocessor character '$'. Compilation failed" And:
I've reworked this routine into a pattern that is probably good programming practice for such things. I've put the end on, even though it never really gets there - it jumps back to the loop bit forever.
Code:
SUB fastcall printstring ()
ASM
;If we are calling routines, we need to make sure we put things back as we found them.
; This routine uses a,bc and de so we'll save those. The ROM calls use HL as well.
PUSH AF
PUSH BC
PUSH DE
PUSH HL
; and now the main routine.
ld a,2 ; upper screen
call 5633 ; open channel
loop:
ld de,string ; address of string
ld bc,eostr-string ; length of string to print
call 8252 ; print our string
jp loop ; repeat until screen is full (this loops forever)
string:
defb "(your name) is cool"
eostr:
; If we were exiting, we'd get to here, so Now we'd recover our saved registers
POP HL
POP DE
POP BC
POP AF
END ASM
END SUB
' Main code
' Let's call our routine
printstring()
' End of program.
Things to note -
I've wrapped this into a ZX Basic Subroutine, so it's called like any other ZX Basic Subroutine.
Labels are followed with a colon. That was the main problem with the original version - it's loop: to have a label called loop.
You can't do label EQU $, but you can subtract the value of one label from another in a very similar way.
Quoting in a DEFB requires " each side, not '
For your other routines, try making labels with a : at the end.
For some examples, have a look at the Wiki: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->
Hope this helps!