Good morning, everyone. I did some calculations in TI-BASIC to fill a list. I have an array in an assembly program that I would like to fill with the all the values in that list. Every time the assembly program is run, it should look to that list to fill the array. If possible, it would be great to use a named list rather than a numbered list. How might I do this?

Thanks
I figured it out! Woohoo!


Code:

   ld b, 4
; input b the size of the list minus one
_LOneToArray:
   push bc
   ld hl, L1Name
   rst rMov9ToOP1
   b_call(_FindSym)
   pop bc
   
   ld a, b
   inc a
   
   push bc
   ld l, a
   ld h, 0
   b_call(_GetLToOP1)
   b_call(_ConvOP1)   ; the desired element is now in DE
   pop bc
   
   push bc
   ld ix, Arr
   call SetArray16

   pop bc
   
   djnz _LOneToArray
; final loop, for when b == 0. small brain but it works
   ld b, 0
   push bc
   ld hl, L1Name
   rst rMov9ToOP1
   b_call(_FindSym)
   pop bc
   
   ld a, b
   inc a
   
   push bc
   ld l, a         ; which element we want
   ld h, 0
   b_call(_GetLToOP1)
   b_call(_ConvOP1)   ; the desired element is now in DE
   pop bc
   
   push bc
   ld ix, Arr
   call SetArray16
   pop bc
   
   ret
   
Arr:
.dw 0, 0, 0, 0, 0

L1Name:
.db ListObj, tVarLst, tL1, 0, 0

; retrieve and print element of arr
; input ix array to get element from
; input b index of element
; output hl is arr[index]
; destroys c
GetArray16:
   ld c, b
   ld b, 0
   
   ld h, b            ; double index
   ld l, c
   add hl, bc
   ld b, h
   ld c, l
   
   add ix, bc         ; offset array by index
   
   ld a, (ix + 0)      ; access array at index and store in hl
   ld l, a
   ld a, (ix + 1)
   ld h, a

   ret

; change and then retrieve and print element of arr
; input ix is array
; input b is index to set
; input de is array[index] = de
; destroys c
SetArray16:
   ld c, b
   ld b, 0

   ld h, b
   ld l, c
   add hl, bc
   ld b, h
   ld c, l
   
   add ix, bc
   
   ld a, e
   ld (ix + 0), a
   ld a, d
   ld (ix + 1), a

   ret
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement