mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-23 07:30:31 +00:00
Add example routine finding min among 3 numbers.
This commit is contained in:
parent
7cf3f263e3
commit
b44dcdc91a
28
examples/min3.s
Normal file
28
examples/min3.s
Normal file
@ -0,0 +1,28 @@
|
||||
; min3
|
||||
; Takes 3 numbers (A, B, C), passed on stack, finds the minimum.
|
||||
; Result is also passed on stack. Assumes it is being called via jsr.
|
||||
.set retl,0x10
|
||||
.set reth,0x11
|
||||
.set res,0x12
|
||||
min3: pla ; pull low byte of return address
|
||||
sta retl
|
||||
pla
|
||||
sta reth
|
||||
pla ; pull C from stack
|
||||
sta res ; save C into res
|
||||
pla ; pull B from stack
|
||||
cmp res ; compare B and C
|
||||
bpl bltc ; branch if B > C
|
||||
sta res ; if C is smaller, save it to res
|
||||
bltc: pla ; pull A from stack
|
||||
cmp res ; compare A and whatever is in res
|
||||
bpl ret ; branch if A > res
|
||||
sta res ; otherwise save A to res
|
||||
ret: lda res ; load res into accumulator
|
||||
pha ; save to the stack
|
||||
lda reth ; restore return address
|
||||
pha
|
||||
lda retl
|
||||
pha
|
||||
rts ; return from function
|
||||
|
Loading…
Reference in New Issue
Block a user