|
Post by stiggity on Jan 2, 2021 0:03:19 GMT
I didnt really _search_ this forum top to bottom but here goes..
any info/writeups on finding, writing, reading multi dimensioned arrays in ASM. I wrote numerous Variable handling assembly routines, but am in need of some help. If it counts for anything, right now, all I want to deal with is the first array dimmed(defined). I'd like to learn how I can create an element, and read any element in the array. ~Also, this is a hybrid program. Both BASIC/ML. But already consists of >250blocks of ML. Thanks again -Steve
|
|
|
Post by bjonte on Jan 2, 2021 3:57:33 GMT
You have created an array in BASIC and want to modify it in assembler?
|
|
|
Post by stiggity on Jan 2, 2021 17:41:54 GMT
I really must read/write to the array in Assembler. Defining (dimming) the array in assembler would be a bonus!! If theres any available source, I would Love to see it..
|
|
|
Post by bjonte on Jan 3, 2021 14:43:13 GMT
I feel that there’s a lot of uncertainty around the question. To use an array you need to have some memory somewhere to store it. Do you have a location for it?
When you know where it is you need to know the size since that affects how simple the solution will be. To read or write into the array you will need a base address and an index register to access the data. Reading byte element 5 in an array starting at $4000 could be done like this.
ldx #5 lda $4000,x
A would now contain the element. This works when storing bytes in an array of no more than 255 elements. If there are more elements it gets trickier. You need to constuct a pointer, in zero page preferrably, and access the data through that pointer.
ldy #0 lda (pointer),y
To construct the pointer you need to add the byte offset to the array start address.
If you need to store larger elements it gets trickier. You then need to calculate an offset by multiplying the element size with the index. Usually you make sure you have sizes of 2^n, which makes it possible to shift instead of multiplying.
|
|
|
Post by stiggity on Jan 5, 2021 21:31:08 GMT
bjonte:
I'm already capable of finding variables, length, and where in memory there stored. Firstly, 255 elements is way more than ample to start off with. My source code is sloppy, and rarely ever commented, but I could leave you a snippet.
Right now, the first array dimmed, should be easy to find/define, and i also have a 255 character buffer with an end of buffer terminator. This buffer (buffer0) hold all the data needed to populate 1 element of the array. Also, once i become familiar with the entire theory, i'd like to read 1 element at a time into
(buffer0), and manipulate that whichever way. I appreciate your help!!! in BASIC=, let's say the first array dimmed is (ed$(255)) i'd `Love to learn how to write an element (1-255) into the array, and/or pull 1 element out of the array into a buffer/variable/both for further processing.
|
|
|
Post by nikoniko on Jan 6, 2021 17:22:03 GMT
Will you need to allow existing strings to be resized? For instance, the string at index 0 is "Hello", but later is changed to "Goodbye". I ask because things become considerably more complicated in that case due to the need for some sort of garbage handling. I wouldn't recommend going that route to start with, or if variable-length strings are essential you could call into BASIC ROM routines and let them do the heavy-lifting. BASIC 7.0's string management is quite good. Really though a hybrid BASIC/ML program may be ideal since it'd let you focus writing ML only for the things where it will provide the most advantage.
Regardless your need, fundamentally somewhere in memory there will need to be a heap to store your string data, and somewhere else a table with pointers to that data. To find out where a string lives in memory, the address needs to be read from the corresponding position in the table. New strings (or new copies of strings which were changed to longer strings) can be added after the most recent entry on the heap until the end of the heap is reached.
I'd suggest starting off more simply to get your feet wet, like a 256 byte or less array of byte values. Get comfortable with indexed addressing modes and loops, then move on to a larger array of byte values. After that, tackle an array of 16-bit values. Then come back to arrays of strings.
|
|
|
Post by stiggity on Jan 6, 2021 23:03:36 GMT
YES... dealing with strings in ASM is a hard job. I created a hack, and with some _back yard coding_ routines, everything works. I know exactly what your getting at. array (ed$(255)) element #1 was "Hello World" and then once changed to "Goodbye" you get "Goodbyeorld" or something of that sense. If i could simply learn how to find an array in ZP and the correct bank, define it, and read from it??? i dont think, right now, that i'll have any need for a 16 bit array.. I'm sort of writing a word processing program.
|
|
|
Post by stiggity on Jan 13, 2021 23:47:38 GMT
source code? links?? it all _sounds_ good!!! but i dont really know where to begin..
|
|
|
Post by stiggity on Feb 8, 2021 18:40:41 GMT
I guess this thread is obsolete..
|
|
|
Post by bjonte on Feb 8, 2021 21:16:31 GMT
// put address in zero page location lda #<array_addr sta $fb lda #>array_addr sta $fc
// write to array ldy #0 // <- element index here lda #64 // <- what to write here sta ($fb),y
// read from array ldy #0 // <- element index here lda ($fb),y // a now has the value at index
|
|