;LP11SIM.ASM - FIR LOWPASS FILTER WITH 11 COEFF FOR SIMULATION
         .start   ".text",0x809900 ;where text begins
         .start   ".data",0x809C00 ;where data begins
         .data                     ;data section
IN_ADDR  .word    INB              ;starting address for input
OUT_ADDR .word    OUTB             ;starting address for output
XB_ADDR  .word    XN+LENGTH-1      ;bottom address of circ buffer
HN_ADDR  .word    COEFF            ;starting addr of coefficients
COEFF    .float   0                ;H10
         .float   0.0468, 0.1009, 0.1514, 0.1872, 0.2
         .float   0.1872, 0.1514, 0.1009, 0.0468
H0       .float   0                ;H0
LENGTH   .set     H0-COEFF+1       ;# of coefficients
INB      .float   10000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
OUTB     .float   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0       
         .brstart "XN_BUFF",16     ;align samples buffer
XN       .sect    "XN_BUFF"        ;section for input samples
         .loop    LENGTH           ;buffer size for samples
         .float   0.0              ;initialize samples to zero
         .endloop                  ;end of loop
         .entry   BEGIN            ;start of code
         .text                    
BEGIN    LDP      @0x809800        ;init to data page 128
         LDI      LENGTH,BK        ;size of circular buffer
         LDI      @XB_ADDR,AR1     ;last sample address ->AR1
         LDI      @IN_ADDR,AR2     ;input address      -->AR2
         LDI      @OUT_ADDR,AR3    ;output address     -->AR3
FILT     LDI      LENGTH-1,AR4     ;length in AR4
LOOP     LDF      *AR2++,R3        ;input new sample
         STF      R3,*AR1++%       ;store newest sample
         LDI      @HN_ADDR,AR0     ;AR0 points to H(N-1)
         LDF      0,R0             ;init R0
         LDF      0,R2             ;init R2
         RPTS     LENGTH-1         ;repeat LENGTH-1 times
         MPYF3    *AR0++,*AR1++%,R0 ;R0 = HN*XN 
||       ADDF3    R0,R2,R2         ;accumulation in R2 
         DBNZD    AR4,LOOP         ;delayed branch until AR4<0
         ADDF     R0,R2            ;last mult result accumulated
         FIX      R2,R7            ;convert float R2 to integer R7
         STI      R7,*AR3++        ;store into output buffer
WAIT     BR       WAIT             ;wait
         .end                      ;end
        













