News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_JohnnyRockets

Newbie ASM question.

Started by JohnnyRockets, 02:05, 05 March 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JohnnyRockets

Hi all!
Newbie question alert!!!

I have commented this code to check my understanding of it.
Am I on track with my understanding?

org &4000
.txt_output equ &bb5a
ld hl,string
call print
ret

; Routine below prints each letter individually until "Hello"
; has been processed one character at a time ->  H-e-l-l-o
; basically looping until a zero is encountered
; the "z" flag will not be set until a zero happens
; and a zero happens at the end of ths string of characters
.print           
ld a,(hl)
cp 0
ret z
call txt_output
inc hl            ;moves over one address space?  Is that correct?
jp print

.string
db "Hello"


Please correct me in any way that you think would be helpful!

Also, where would one find a CPC486 User's Manual for download?

Thanks!


JR   ;D

roudoudou

You must add a zéro at the end of the string. You cannot presume the ram is blank as default


dthrone

You can replace 'cp 0' with 'or a' to save a byte.  Longer programs usually end up with lots of cp 0s so those bytes do add up!
SOH Digital Entertainments

SRS

As mentioned above: you need a "db 0" after string. My 2cents in comments
org &4000
.txt_output equ &bb5a
ld hl,string
JP print ; instead of call print and ret -> save Byte and time
;ret

; Routine below prints each letter individually until "Hello"
; has been processed one character at a time ->  H-e-l-l-o
; basically looping until a zero is encountered
; the "z" flag will not be set until a zero happens
; and a zero happens at the end of ths string of characters
.print           
ld a,(hl)
or a ; works like "cp 0" but saves RAM
ret z
call txt_output
inc hl            ;moves over one address space?  Is that correct? YES
jr print; instead of "jp print" you can "jump relative" for this short distance,JR takes up one less byte than JP, but is also slower

.string
db "Hello"
db 0

JohnnyRockets

Thanks everyone for your input!

I'm going to analyze the code a bit more with your additional suggested changes.  I'm very new to ASM so it's a lot to take in and I have to go very sloooowww, LOL!  :)

Once I analyze it a bit, I'm sure I'll have more questions.


JR

Powered by SMFPacks Menu Editor Mod