Passing Records by Reference to Function/Procedure

28 views
Skip to first unread message

Saumitra Deshpande

unread,
May 10, 2026, 3:10:55 AM (2 days ago) May 10
to jallist
Hi,

Is there a way to pass a record by reference to a function or procedure ?

I need multiple FIFO queues for my project, but jallib implements this as multiple libraries, each identical to other in code, but maintaining separate data.  (queue01.jal, queue02.jal...queue08.jal...etc)

That is a lot of waste of code-space which I can't afford. Passing record by reference to can remedy that. But I can't find a way to do it. Jal passes records by value, so any array within record gets duplicated before function call & written after the function call. Again lot of code space as well as RAM if buffers are large.

Also in queue01.jal, there is declaration,

var volatile byte*queue01_element_size queue01_data[queue01_size + 1]

And later, 

function queue01_nb_get(byte*queue01_element_size out v) return bit is
...
v = queue01_data[queue01_out_pointer]
...
end function

What exactly is this "byte*xxx" syntax ? 

Thanks,
sam_des


Rob CJ

unread,
May 10, 2026, 12:29:23 PM (2 days ago) May 10
to jallist
Hi Samaumitra,

When I pass a record to a procedure I see in the assembly listing that it clears all values of the record and then calls the procedure which then uses the cleared values. I do not know why the compiler clears the record since that introduces a lot of code each time you call a procedure. Does not seem necessary - and maybe even incorrect - or I must be missing something. I may have a look at the compiler source code where this is done. 

The byte* construction can be found in the compiler documentation.

byte*2 are 2 bytes so a word and byte*4 are 4 bytes so a dword. 

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Saumitra Deshpande <sam1...@gmail.com>
Verzonden: zondag 10 mei 2026 06:27
Aan: jallist <jal...@googlegroups.com>
Onderwerp: [jallist] Passing Records by Reference to Function/Procedure
 
--
You received this message because you are subscribed to the Google Groups "jallist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallist+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallist/6c805b64-a452-47a4-9551-0a66ffe9afd5n%40googlegroups.com.

Saumitra Deshpande

unread,
May 11, 2026, 12:56:29 PM (yesterday) May 11
to jallist
HI Rob,

Thanks for clarification on byte*xx. 

Regarding record, I get the code that does not clear the record before calling. I tried simple code as following,

jal code---
record test is
    byte a
    byte b
end record

var test t

procedure change_record(test in out t) is
    t.a = t.a + 1
    t.b = t.b + 1
end procedure

--
change_record(t)

Generated code --
   48 procedure change_record(test in out t) is
l_change_record
;   49     t.a = t.a + 1
                               incf     v___t_2,f,v__access
;   50     t.b = t.b + 1
                               incf     v___t_2+1,f,v__access
;   51 end procedure
                               return  

;   86 change_record(t)
                               movf     v_t,w,v__access
                               movwf    v___t_2,v__access
                               movf     v_t+1,w,v__access
                               movwf    v___t_2+1,v__access
                               call     l_change_record
                               movf     v___t_2,w,v__access
                               movwf    v_t,v__access
                               movf     v___t_2+1,w,v__access
                               movwf    v_t+1,v__access

Clearly, record "t / v_t" is getting copied into a new record "v___t_2" before call to change_record() & new values in t_2, modified by called procedure, gets copied back into original record t.
As correct pass by value mechanism as usual.

And if record has an array in it, code generated duplicates entire array to new one. Code is ok, but very inefficient for rom/ram.

I can get the address of record using whereis(t). But it can be only passed as byte/word to procedure/function, which has no idea how to interpret it. 

sam_des

Rob CJ

unread,
May 11, 2026, 1:29:25 PM (yesterday) May 11
to jallist
Hi sam_des,

I had an array in my test, maybe that was it. 

If you would use whereis and pass that address as parameter, could you not write some assembly code in your procedure to change the value?

So if you would define a word variable 'address' and use 'address = whereis(t)' then pass the address to the procedure and use the address to modify what you want to modify. You could  look at the memory_pointer library for inspiration.

Kind regards,

Rob


Verzonden: zondag 10 mei 2026 18:52
Aan: jallist <jal...@googlegroups.com>
Onderwerp: Re: [jallist] Passing Records by Reference to Function/Procedure
 
Reply all
Reply to author
Forward
0 new messages