Catamorphism: Difference between revisions
no edit summary
m (→Excel LAMBDA) |
Puppydrum64 (talk | contribs) No edit summary |
||
Line 25:
7
</pre>
=={{header|6502 Assembly}}==
=={{works with|https://skilldrick.github.io/easy6502/|Easy6502}}==
<lang 6502asm>define catbuf $10
define catbuf_temp $12
ldx #0
ramloop:
txa
sta $00,x
inx
cpx #$10
bne ramloop
;load zero page addresses $00-$0f with values equal
;to that address
ldx #0 ;zero X
loop_cata:
lda $00,x ;load the zeroth element
clc
adc $01,x ;add the first to it.
inx
inx ;inx twice. Otherwise the same element
;would get added twice
sta catbuf_temp ;store in temp ram
lda catbuf
clc
adc catbuf_temp ;add to previously stored value
sta catbuf ;store in result
cpx #$10 ;is the range over?
bne loop_cata ;if not, loop again
ldx #$00
lda catbuf
sta $00,x
;store the sum in the zeroth entry of the range
inx
lda #$00
;now clear the rest of zeropage, leaving only the sum
clear_ram:
sta $00,x
inx
cpx #$ff
bne clear_ram</lang>
=={{header|ABAP}}==
This works in ABAP version 7.40 and above.
|