Re: A86: For( loops and Lists


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

Re: A86: For( loops and Lists




(sorry i sent an empty email earlier.  aol sucks, as you all know.)


In a message dated 8/25/99 1:28:32 PM Eastern Daylight Time, 
Jeanne9005@aol.com writes:

> I am porting and converting a program and was wondering 2 things.
>  
>  1) How would I go about using a For( style loop in my program?

the easiest way is to use the b register as a counter and djnz for the 
looping.  for example:

    ld b,5              ;loop 5 times
loop:
    push bc             ;save counter
    ...code
    pop bc              ;retrieve counter
    djnz loop           ;decrement b and loop if b isn't 0

>  
>  2) How do I get a number that is at the Xth point in a list?  In BASIC, I 
>  know I can just say LIST(X), but how do I do this in ASM?

that depends on what you mean by a list.  if it's just a bunch of bytes one 
after another, you would do something like this:

get_list_element:
    ;input:
    ;   element # in a
    ;output:
    ;   a=value in list
    ld hl,list
    ld e,a
    ld d,0
    add hl,de
    ld a,(hl)               ;get element
    ret

list:
    .db 5,3,2,5,7,3,8,5,3,8,4,3,0,3,2           ;the list is stored like this

it would be somewhat different if you were actually dealing with real list 
vars.