當您將參數傳遞給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