I think I see the problem! :twisted:

Function:
Code:
   mul   r0,r2,r0  # In other words: the function stores i*j in r0
   bl   P$FILLSCREEN_FPC_MODULUS$LONGINT$LONGINT$$LONGINT
RTL:
Code:
  mov r0,#31  # In other words, the rtl stores #31 in r0
  bl   fpc_mod_longint
In other words, the parameters are reversed!!

Try this:

[pascal]
function fpc_mod_longint(n,z: longint):longint; compilerproc; assembler; [public, alias: 'FPC_MOD_LONGINT'];
asm
; Reverse the parameters!
mov r2,r0
mov r0,r1
mov r1,r2
; Do software interrupt.
swi #0x060000
mov r0, r1
end['r0','r1','r2','r3'];
[/pascal]