# RE: LZ: Question with programming

```On Tue, 10 Dec 1996 21:44:39 -0500,
Ryan Myers wrote...
>I am thinking of using a matrix-style level system for a new game...
>
>This is the code I figured would do the job; could anyone inform if this
>would work, as I just broke my link yesterday by popping off the cable,
and
>I don't have time lately between school and work to make a new one yet.
>
>
>-----------------------------BEGIN
>SNIPPET------------------------------------
>
>The Matrix would be like this:
>
>Matrix1:
>        .db 6, 6, 6, 6, 6, 6
>        .db 6, 6, 6, 6, 6, 6
>                ...
>        .db 6, 6, 6, 6, 6, 6
>
>For a total of 12 rows of 6 wide, containing values 0, 1, 2, 3, 4, 5, or
6.
>
>This would be the code to retrieve a value at row x, column y - assuming
>that
>the first value in the matrix is row 0 col 0 and the last row 11 col 5.
>Row
>is given in B and Column in A.
>
>GetValue:
>        mul b, 6
>        ld hl, a
>        ld a, (hl)
>        ret
>

There is no multiplication instruction in assembly language.  Your
instruction mul b, 6 is invalid and will not work.  To do any
multiplication you must use a routine which shifts the multiplier to the
right, tests the carry bit.  If the carry bit is set, you add the
multiplicand to your result (at this point, zero) then shift the
multiplicand one to the left.  Then you repeat until you are done with your
eight bits.

Also, there is no ld hl, a command in Z80 assembly.  a is an eight bit
register, while hl is a sixteen bit register, and you cannot load an eight
bit register into a sixteen bit register.  The closest you could come is to
load a into l (make sure h is zero), then add that to Matrix1, then add the
program offset, THEN you would have the address of the byte you wanted to