我正在努力将两个数组加在一起。我不知道在addsp 2,i
之后是否需要addsp 6,i
,然后将其存储到num3
中。我也不知道该如何处理进位。
add: nop0
subsp 6,i ; for parameters and result of larger
ldwa num1,i ; load num1
stwa 0,s ; store num1
ldwa num2,i ;load num2
stwa 2,s ; store number 2
call larger ; larger(num1,num2)
addsp 6,i ; add to stack
ldwa -2,s ; result of comparison
brlt add2 ; branch if num1 < num2
;
subsp 6,i ; for parameters of add. num3=num1+num2
ldwa num1,i ; load number 1
stwa 0,s ; store number 1
ldwa num2,i ; load number 2
stwa 2,s ; store number 2
ldwa num3,i ; load number 3
stwa 4,s ; store number 3 under 4
call add ; add (num1,num2,num3)
addsp 6,i ; add to the stack
addsp 2,i ; for output
ldwa num3,i ; store in number 3 the results
call output ; output(num3)
ret
;
;
add2: stro ADD,d ; display add message
subsp 6,i ; for parameters of add. num3=num2+num1
ldwa num2,i ; load number 1
stwa 0,s ; store number 1
ldwa num1,i ; load number 2
stwa 2,s ; store number 2
ldwa num3,i ; load number 3
stwa 4,s ; store number 3
call add ; add (num2,num1,num3)
addsp 6,i ; add to stack pointer
addsp 2,i ; for output
ldwa num3,i ; save the added numbers to num3
call output ; output(num3)
ret
;