Msx Basic array to asm

By PingPong

Prophet (3460)

PingPong's picture

18-09-2018, 14:23

How i can Pass a int [] array via usr ti a machine language sub getting both ptr to data and size of array?

Login or register to post comments

By gdx

Prophet (3085)

gdx's picture

18-09-2018, 14:37

See here:
And here:
if you want more information about variables format and more.

By Eugeny_Brychkov

Paragon (1106)

Eugeny_Brychkov's picture

18-09-2018, 15:20

10 defint a:dim a[20]
20 a[0]=100:a[1]=200
30 defusr=&hc000:a=usr(varptr(a[0]))

In this code routine at &hc000 is called with HL pointing to DAC, and HL+2 (DAC+2) containing pointer to the start of the array (element a[0]). I think it is fair to expect that array is contiguous, thus (DAC+2) + 10 will point to word of a[5].

Here's format (example of bi-dimensional array from here):

    |     |     |     |  Offset   | Dim |   Count   |   Count   |
    | 02H | "A" | "B" | 2DH   00H | 02H | 05H   00H | 04H   00H |

(DAC+2) pointing to the first byte after the array, thus if you know it is single dimensioned array you move pointer -2 bytes and read word of the array's size. Move pointer another byte position -1 will give you 1 (single dimension).

I do not think it is possible to pass pointer to array this way; alternatively you can pass name of array to USR as a string, and use PTRGET to know pointer to the array - playing with SUBFLG. But it needs testing.

By PingPong

Prophet (3460)

PingPong's picture

18-09-2018, 19:46

Thx to all expecially to Eugeny. I've noticed the unusual double type storage format, wondering if this have or not speed benefits compared to IEEE like formats that are full & true binary based.