SMProxy

Untitled

May 13th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. .macro call(func, args...) ; ABI-style function call with any number of arguments
  2. .for i=0, i<args_length, i++
  3. .if i = 0
  4. SET A, args[i]
  5. .elseif i = 1
  6. SET B, args[i]
  7. .elseif i = 2
  8. SET C, args[i]
  9. .else
  10. SET PUSH, args[i]
  11. .end
  12. .end
  13. JSR func
  14. .if args_length - 3 > 0
  15. ADD SP, args_length - 3 ; clean up stack
  16. .end
  17. .endmacro
  18.  
  19. call(function, 10, 14, 27)
  20.  
  21.  
  22. ; Again, but this time, optimized to not re-set registers
  23.  
  24. .macro call(func, args...) ; ABI-style function call with any number of arguments
  25. .for i=0, i<args_length, i++
  26. .if i = 0
  27. .if args[i] !== A
  28. SET A, args[i]
  29. .end
  30. .elseif i = 1
  31. .if args[i] !== B
  32. SET B, args[i]
  33. .end
  34. .elseif i = 2
  35. .if args[i] !== C
  36. SET C, args[i]
  37. .end
  38. .else
  39. SET PUSH, args[i]
  40. .end
  41. .end
  42. JSR func
  43. .if args_length - 3 > 0
  44. ADD SP, args_length - 3 ; clean up stack
  45. .end
  46. .endmacro
  47.  
  48. call(function, A, B, C) ; This is just JSR func thanks to the auto-optimization
Advertisement
Add Comment
Please, Sign In to add comment