int8_t a
uint16_t b
uint16_b c
We need to get uint32_t sum which can be get by the next formula
sum += 0, if a = 0 (A)
sum += 3b, if a > 0 (B)
sum += c, if a < 0 (C)
The code for the 6502 can be such
Code: Select all
;sum - 4 zp bytes
;tab_addr - 2 zp bytes
;cnt - 2 zp bytes
;t - 2 zp bytes
lda #0
sta sum
sta sum+1
sta sum+2
sta sum+3
lda #lo(tab)
sta tab_addr
lda #hi(tab)
sta tab_addr+1
lda #lo(65536-COUNT)
sta cnt
lda #hi(65536-COUNT)
sta cnt+1
loop
ldy #0
lda (tab_addr),y
beq next
bmi alt
ldy #2 ;offset of hi(b)
lda (tab_addr),y
sta t1
dey
lda (tab_addr),y
asl
tax
rol t1
lda #0
rol
sta t1+1
txa
adc (tab_addr),y
tax
iny
lda (tab_addr),y
adc t1
sta t1
bcc l1
inc t1+1
l1 txa
clc
adc sum
sta sum
lda t1
adc sum+1
sta sum+1
lda t1+1
adc sum+2
sta sum+2
bcc next
bcs l4
alt ldy #3 ;offset of lo(c)
lda (tab_addr),y
clc
adc sum
sta sum
iny
lda (tab_addr),y
adc sum+1
sta sum+1
bcc next
inc sum+2
bne next
l4
inc sum+3
next
lda tab_addr
clc
adc #5 ;size of the record
sta tab_addr
bcc l3
inc tab_addr
l3 inc cnt
bne loop
inc cnt+1
bne loop
What can the 6800 show?