two-passes

A program of Temporaries and Liveness.

main.ngp

modules { "scan.asm" }

scan.asm

; tag data
.section
input
        .byte 3, 1, 4, 1, 5
.ends

.section zeropage
largest
        .res 1
.ends

.section zeropage
above
        .res 1
.ends

; end data

; tag body
.proc entry
best    .ztemp 1
tally   .ztemp 1

        lda #0
        sta best
        ldx #4
@pick   lda input,x
        cmp best
        jcc @kept
        sta best
@kept   dex
        bpl @pick
        lda best
        sta largest

        lda #0
        sta tally
        ldx #4
@count  lda input,x
        cmp #3
        jcc @next
        inc tally
@next   dex
        bpl @count
        lda tally
        sta above
        rts
.endp
; end body

Memory map

  1. phase03 zero page, 50 bytes
AddressBytesSectionModuleKindPhasesWaits
$0080–$00801largestscansection0
$0081–$00811abovescansection0
$0082–$00821entry.bestscantemporary0
$0082–$00821entry.tallyscantemporary0
$2000–$20045inputscansection0
$2005–$203145entryscanproc0