当您将参数传递给 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