[A83] Re: storing op1 to list


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

[A83] Re: storing op1 to list




Create the first list as explained in asmGuru.
    ...
    bcall(_createRList)
    ld    (list1),de

Create the second list.
    ...
    bcall(_createRList)
    ld    (list2),de

    ...(Calculate Number in OP1)...

Store OP1 in list1.
    ld    de,(list1)
    ld    hl,1
    bcall(_AdrLEle)
    ex    de,hl
    bcall(_MovFrOPl)
    ...

variables:
list1:
    .dw   0000h
list2:
    .dw   0000h
.end

===================================

What happens is this. You create the first list and you store its location in a safe place. The second list is exactly the same. When you then have a number in OP1 and want to store it in the list, you get the location of that list again. Then you calculate the address of the element in the list and then you just copy the bytes in OP1 to that element.
( The _MovFrOP1 romcall just copies 9 bytes FRom OP1 to the location where DE is pointing to. If, however, you are optimizing for speed you should use a simple LDIR instead. )


> ----------------------------------------
> From: TypeR unknown <typerfuture@hotmail.com>
>
>I have this program where in the beginning of the program two lists are
>created, named ZG1 and ZG2.
>In testing I have used the number 5 for the number of element's they both
>contain.
>
>Later in the program I have to write the number which is in op1 to a
>element in list ZG1, to do this I have used the code as given in ASMGURU
>(tut 31 I believe)
>It goes like this:
>
>    ld hl,1 ;write to element 1
>    call _adrlele ;calculate element address
>    ex de,hl  ;de->element address
>    ld hl,op1 ;hl-> number
>    ld bc,9
>    ldir   ;store to element
>
>but because there is a lot of code between creating the list and actually
>writing to it, as far as I know, I must preserve the de register because
>this contains the list element.
>
>So I have saved de with two user defined variables (not good but I think
>reliable), but the program doesn't work well, because it doesn't store the
>number!!!
>
>Should I be preserving more registers, or is the something wrong with my
>code??

-----------------------------------------------------
Mail.be, Free WebMail and Virtual Office
http://www.mail.be





Follow-Ups: