Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .macro call(func, args...) ; ABI-style function call with any number of arguments
- .for i=0, i<args_length, i++
- .if i = 0
- SET A, args[i]
- .elseif i = 1
- SET B, args[i]
- .elseif i = 2
- SET C, args[i]
- .else
- SET PUSH, args[i]
- .end
- .end
- JSR func
- .if args_length - 3 > 0
- ADD SP, args_length - 3 ; clean up stack
- .end
- .endmacro
- call(function, 10, 14, 27)
- ; Again, but this time, optimized to not re-set registers
- .macro call(func, args...) ; ABI-style function call with any number of arguments
- .for i=0, i<args_length, i++
- .if i = 0
- .if args[i] !== A
- SET A, args[i]
- .end
- .elseif i = 1
- .if args[i] !== B
- SET B, args[i]
- .end
- .elseif i = 2
- .if args[i] !== C
- SET C, args[i]
- .end
- .else
- SET PUSH, args[i]
- .end
- .end
- JSR func
- .if args_length - 3 > 0
- ADD SP, args_length - 3 ; clean up stack
- .end
- .endmacro
- call(function, A, B, C) ; This is just JSR func thanks to the auto-optimization
Advertisement
Add Comment
Please, Sign In to add comment