Re: LZ: matrices


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

Re: LZ: matrices



list-zshell@defiant.rbk.sollentuna.se wrote:
> 
>                                    wstokes@vertex.ucls.uchicago.edu
>                                    http://www.uic.edu/~hhstokes/index.html
>                                    Will Stokes
> 
> Earlies I asked about stacks and i got one answer but I could completely
> follow it. Here is my refined q into two parts with specific boundries.
> Here it goes...if anybody could respond on how to solve these situations
> it would be very helpful..thanks!!
> 
> Part 1:         Basic Matrices
> 
>         Ok, it is to my knowledge that matrices are possible in Z-80
> assembler implemented on ZShell. Give the following parameters can anbody
> provide the complete code including matrix??
> 
> a simple 6 by 2 matrix  [1  2  5  4  8  9]
>                         [6  4  1  1  3  2]
> 
> for a certain values of "Down" and "Side" load a value from the matrix
> above into "Value"
> 
> Matrix called MTX
> 
> Down = TEXT_MEM
> Side = TEXT_MEM+1
> 
> Ok, can anbody solve that? Seems pretty simple to me...just don't know
> how in assembler.
> 
> Part 2:         Using matrices for mangage strings.
> 
> Matrix "MTX2" 2 by 3 given MTX2 = [Bob   Brian  Mary]
>                                   [Dave  Meg    Josh]
> like above given calcues of "Side" and "Down" load a string from MTX2 into
> DE and STR.
> 
> A little tougher but that same sorta thing.
> 
>         If anybody out there can provide me code to do this stuff that
> works it would be much appreciated.
>                         Talk to you later,
>                         Will Stokes
> 


Basically for a numerical matrix, you allocate memory, for this purpose,
lets allocate some memory at 1000h (to make things easy, this isnt a ram
location, but what the heck..). Say you want a 2 x 4 matrix of char
(1-byte number). Then all you have to do is allocate 8 bytes of memory
(2 x 4 = 8). Load ix with the value of the starting element (well, you
can use hl, but then you have to do adds and stuff). Remember, your
array dimensions are (0-1) x (0-3). Now you just calculate the offset.
Lets say this is what the array looks like drawn out as an array.


  3 7
  2 4
  5 1
  6 8


This is how it would look in memory (with a hex editor)


03 07 02 04 05 01 06 08


If you wanted to access the element that contained '4', you just have to
find the offset and do a


ld a, (ix+3)


to do strings in an array, you can either declare more room for each
element, or you can make each element a pointer to a string.


<pre>
-- 


--Steve
s_wrobleski@foma.wsc.mass.edu
</pre>


References: