IZIShadowIZI 0 Newbie Poster

I believe I have the correct implementation down but I think I have some sort of problem with my return? When I input 4 the program will execute and eventually reach 24 however it then continues on and I am not sure what the problem is? Any help would be greatly appreciated THANKS!

ldx 0x0000, i
lda 0x0000, i
deci input, d
ldx input, d
stx -2, s
subsp 2, i
ldx input, d
stx -2, s
subsp 2, i
lda input, i
stx -2, s
subsp 2, i
call fac
deco 0, s
stop

fac: lda 6, s
addsp 2, i
cpa 0x0001, i
brgt recurse
stx 6, s
ret0

recurse: suba 0x0001, i
sta 4, s

add:suba 0x0001, i
addx 0, s
stx 2, s
cpa 0x0001, i
brgt add
stx 0, s
call fac
ret0

input: .block 2
.end
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.