abi4.ssa 612 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # return a large struct to C
  2. type :mem = { b 17 }
  3. function $alpha(l %p, w %l, l %n) {
  4. @ini
  5. %pe =l add %p, %n
  6. @lop
  7. %p1 =l phi @ini %p, @lop %p2
  8. %l1 =w phi @ini %l, @lop %l2
  9. storeb %l1, %p1
  10. %p2 =l add %p1, 1
  11. %l2 =w add %l1, 1
  12. %c1 =w ceql %p1, %pe
  13. jnz %c1, @end, @lop
  14. @end
  15. storeb 0, %pe
  16. ret
  17. }
  18. export
  19. function :mem $test() {
  20. @ini
  21. %p =l alloc4 17
  22. %r0 =w call $alpha(l %p, w 65, l 16)
  23. ret %p
  24. }
  25. # >>> driver
  26. # #include <stdio.h>
  27. # typedef struct { char t[17]; } mem;
  28. # extern mem test(void);
  29. # int main() { mem m = test(); printf("%s\n", m.t); return 0; }
  30. # <<<
  31. # >>> output
  32. # ABCDEFGHIJKLMNOP
  33. # <<<