Re: A86: Counting Program?


[Prev][Next][Index][Thread]

Re: A86: Counting Program?



At 08:01 PM 9/3/97 -0700, you wrote:
>Jesse Celeste wrote:
>
>> I was wondering if anyone could help me.  I am trying to write a
>> simple
>> asm code that will count backwards from just about any number, like
>> 1000.  Could anyone here on this list help me out and write a sample
>> code that will achieve this purpose.  Every time I try it, i keep
>> getting errors.  Thanx a lot.
>
>
>  ld de,##  ; put your number here 0-65535
>
>  ld b,d        ; do the outer loop this many times
>Part1:
>  push bc     ; we need to save this for the outer counter
>  ld b,e        ; do the inner loop this many times
>  dec de,256  ; you might have to make this three lines
>                     ; (ex hl,de: dec hl,256: ex hl,de) (sorry i'm not
>testing this code..)
>Part2:
>  push bc    ; .
>  push de    ; we need to save these two
>  ;****** your number that is going from ## -> 0 is DE+B
>  pop de     ; get this back
>  pop bc     ; get this back
>  djnz Part2     ;
>  ;**** right here b = 0 so here your number is just DE..
>  ;****  you need to run what you did up there  here too!  (maybe call a
>routine)
>  ;**** make sure you push/pop bc or de if needed
>  pop bc    ; get our outer loop counter back
>  djnz Part1
>  ;**** at this point our number (DE+B) will be zero, if needed repeat
>your
>  ;**** desired routine here
>
>


For a two-byte number (0-65535), an easier way to implement a loop (if in
fact that's what you want to do?) would be:

////////////
	ld de,$FFFF	;or any other number
LoopTime:
	ld a,e
	or d		;or's d with e, findsd if _anything_ is set
	jr z,NewCode	;if at zero, go to new stuff
	push de		;assuming you want to save de
	...	
	loop code here
	...

	pop de		;and get it back if you want
	dec de		;dec number
	jr LoopTime

NewCode:
	Put next code to execute here

///////////

I think this is the best way to do it, there's probably a way to svae a
byte or two somewhere...

P.S. - What the heck kind of command is <dec de,256>?


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Alan Bailey            mailto:bailela@charlie.cns.iit.edu
 IRC:Abalone              Web:http://www.iit.edu/~bailela/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 


References: