Sure! This is what was added to the file "demo_F32.spin" in the latest version of the F32 object in the OBEX:
(of course it is showing Add instead of Mul or Div, but you get the picture)
Code:
{{
This portion of the demo shows the calling convention used by PASM.
F32 expects a vector of 3 sequential longs in Hub RAM, call them:
"result a b"
F32 also has a pointer long "f32_Cmd". The calling goes like this:
result := the dispatch call command (e.g. cmdFAdd)
a := the first floating point encoded parameter
b := the second floating point encoded parameter
Now the vector is initialized, you set "f32_Cmd" to the address of
the start of the vector:
f32_Cmd := @result
Just wait until f32_Cmd equals 0, and by then the F32 object wrote
the result of the floating point operation into "result" (the
head of the input vector).
}}
PUB demo_F32_pasm | timeout
' The PASM calling cog needs to know 2 base addresses
F32_call_vector[0] := f32.Cmd_ptr
F32_call_vector[1] := f32.Call_ptr
' start up the demo cog
cognew( @F32_pasm_eg, @F32_call_vector )
' and just print some stuff
timeout := cnt
repeat
' print it out
term.str( fs.FloatToString( F32_call_vector[2] ) )
term.tx( 13 )
' wait
waitcnt( timeout += clkfreq )
DAT ' this is the F32 call vector (3 longs)
' Note: all 3 are initialized to 0.0 (the Spin compiler can do fp32 constants)
F32_call_vector long 0.0[3]
ORG 0
F32_pasm_eg ' read my pointer values in
mov t1, par
rdlong cmd_ptr, t1
add t1, #4
rdlong call_ptr, t1
' initialize vector[1] (1st parameter) to 1.0
wrlong increment, t1
demo_loop ' load the dispatch call into vector[0]
mov t1, #f32#offAdd
add t1, call_ptr
rdlong t1, t1
wrlong t1, par
' call the F32 routine by setting the command pointer to non-0
mov t1, par
wrlong t1, cmd_ptr
' now wait till it's done!
:waiting_loop rdlong t1, cmd_ptr wz
if_nz jmp #:waiting_loop
' Done! vector[0] = vector[1] + vector[2]
rdlong t1, par
' update my 2nd parameter, and do this all over again
mov t2, par
add t2, #8
wrlong t1, t2
jmp #demo_loop
increment long 1.0e6
cmd_ptr res 1
call_ptr res 1
t1 res 1
t2 res 1
Jonathan
Bookmarks