It was thus said that the Great Iggy Drougge once stated:
Jeffrey S. Sharp skrev:
I've always thought that one of the more
simple assembly languages would
be a great 'first language' for someone wanting to learn how to program.
Who's with me?
Most assemblers haven't got a PRINT statement, so, no, I don't think so.
Depends upon the environment. Under AmigaOS you have RawDoFmt(), which is
part of Exec and available to Assembly language programmers (and it works
similar to C's printf()). Under MS-DOS you have INT 21h, funtion 9, which
prints a text string (ended by a `$'). But all you really need is a way to
print out characters, leaving printing of numeric values as a programming
exercise. In fact, writing a printf()-like routine (no formatting, just
stuff like `%d' and `%s') is fairly simple (6809 code):
**********************************************
* PRINTF - a printf()-esque routine.
* Entry: X - ASCIIZ string
* U - user data stack
* Exit: X - end of string
* U - adjusted as data is used
* A - 0
***********************************************
PRFT50 LDA ,X+ ; get next character after %
CMPA #'% ; %?
BEQ PRTF20 ; if so, print it
CMPA #'d ; print a decimal number?
BNE PRTF51
PULU D ; get value
BSR DECOUT ; print it
BRA PRINTF ; continue
PRTF51 CMPA #'x ; print hex number?
BNE PRTF52
PULU D ; get value
BSR HEXOUT ; print hex value
BRA PRINTF
PRTF52 CMPA #'s ; print string?
BNE PRTF20
PSHS X ; save current string
PULU X ; get new string
BSR PRINTF ; print it (oooh! recursion!)
PULS X ; get old string
BRA PRINTF
PRTF10 CMPA #'% ; print data?
BEQ PRFT50 ; if so, handle
PRTF20 JSR CHROUT ; print character
PRINTF LDA ,X+ ; get next character
BNE PRTF10 ; if not NUL, continue
RTS
Now all that's left is writing CHROUT (or assume the system has such a
routine), DECOUT and HEXOUT (HEXOUT is trivial, DECOUT may make some work).
It's all a part of learning.
-spc (Who wishes that Assembly was tought as a first language ... )