当您将参数传递给CPU堆栈上的函数时,您将参数放在上面,然后JSR将返回地址放在堆栈上。 所以,在你的函数意味着你必须把堆栈(返回地址) 的顶部项目之前,你可以走别人关)在堆栈上传递参数
返回值按照惯例存储在寄存器D0
。
例如如下去做正确的方法:
...
|Let’s do some addition with a function,
MOVE.L #4, -(SP)
MOVE.L #5, -(SP)
JSR add
|the result of the addition (4+5) is in D0 (9)
...
add:
MOVE.L (SP)+, A1 |store the return address
|in a register
MOVE.L (SP)+, D0 |get 1st parameter, put in D0
MOVE.L (SP)+, D2 |get 2nd parameter, put in D2
ADD.L D2, D0 |add them,
|storing the result in D0
MOVE.L A1, -(SP) |put the address back on the
|Stack
RTS |return