three-procs

A program of Temporaries and Liveness.

main.ngp

modules { "scan.asm" }

scan.asm

.section
input
        .byte 3, 1, 4, 1, 5
.ends

.section zeropage
largest
        .res 1
.ends

.section zeropage
above
        .res 1
.ends

.section zeropage
spread
        .res 1
.ends

.proc entry
        jsr findLargest
        jsr countAbove
        jsr report
        rts
.endp

.proc findLargest
best    .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
        rts
.endp

.proc countAbove
tally   .ztemp 1
        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

; tag report
.proc report
least   .ztemp 1
        lda #$FF
        sta least
        ldx #4
@pick   lda input,x
        cmp least
        jcs @kept
        sta least
@kept   dex
        bpl @pick
        jsr findLargest
        lda largest
        sec
        sbc least
        sta spread
        rts
.endp
; end report

Memory map

  1. phase05 zero page, 90 bytes
AddressBytesSectionModuleKindPhasesWaits
$0080–$00801largestscansection0
$0081–$00811abovescansection0
$0082–$00821spreadscansection0
$0083–$00831countAbove.tallyscantemporary0
$0083–$00831findLargest.bestscantemporary0
$0084–$00841report.leastscantemporary0
$2000–$20045inputscansection0
$2005–$200E10entryscanproc0
$200F–$202523findLargestscanproc0
$2026–$203C23countAbovescanproc0
$203D–$205929reportscanproc0