Re: A86: Counting Program?


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

Re: A86: Counting Program?



I caught a small error in my recent reply!  this is the corrected
version!

for numbers > 256

  ld de,##  ; put your number here 0-65535
  ld b,d        ; do the outer loop this many times
  ld a,e        ; do the inner loop this many times first, then 255
times
  ld e,0        ; set DE to just D*256 not D*256+E
Part1:
  push bc     ; we need to save this for the outer counter
  dec d        ; D will have same value as outer loop + 1 (same as
DE=DE-256)
  ld b,a        ; do the inner loop this many times
Part2:
  push bc    ;  save our counter!
  push de    ; save value of d
  ;****** 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
  ld a,255  ; repeat inner loop 256 times next time!
  djnz Part1
  ;**** at this point our number (DE+B) will be zero, if needed repeat
  ;**** yous desired routine here

sorry

there, that should fix those small errors, i didn't catch.  Maybe next
time I should test my routine before posting.. This one still isn't
tested :)  I'll test it tommorow :)

Trent Lillehaugen
Computer Engineering Major
California Polytechnic University, San Luis Obispo
<tllilleh@polymail.calpoly.edu>


References: