Re: A86: Counting Program?


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

Re: A86: Counting Program?



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.

that would be simple for any number < 256, just do this

  ld b,#  ; put your number here
Counter:
  push bc   ; don't know what you plan on doing here
  ;***** now add what you want to do (ie disp the number)
  pop bc    ; this was in case you changed the value of b..  you need it
back
  djnz Counter

that would be it for a number <256, for one >256 you could maybe try
this:

  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



I believe this will work, I haven'ted tested it, just thought of it
while writing the email, but try that, maybe adjust a few things, but
i'm pretty sure this will do the jonb.  Please comment on this idea.

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


Follow-Ups: References: