OpenCores
URL https://opencores.org/ocsvn/copyblaze/copyblaze/trunk

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [sw/] [code/] [kcpsm/] [stack_test/] [SumValue.psm] - Rev 69

Go to most recent revision | Compare with Previous | Blame | View Log

; this programm calculate the sum of the "value" 16bit.
; value = 5; total = 5 + 3 + 2 + 1 = 15
; the result is 16bit outputed 
                CONSTANT        WAVEFORM_PORT, 02
                CONSTANT        COUNTER_PORT, 04

                NAMEREG s0, total_low
                NAMEREG s1, total_high
                NAMEREG s8, value
                
start:
                LOAD    value           ,       1F                              ; find sum of all values to 31
                LOAD    total_low       ,       00                              ; clear 16-bit total
                LOAD    total_high      ,       00                              ; 

                CALL    sum_to_value                                    ; calculate sum of all numbers up to value

                OUTPUT  total_high      ,       COUNTER_PORT    ; Result will be 496 (01F0)hex
                OUTPUT  total_low       ,       WAVEFORM_PORT   ; 
                
end:
                JUMP    end
                ;
                
                ; Subroutine called recursively
sum_to_value:
                ADD             total_low       ,       value                   ; perform 16-bit addition
                ADDCY   total_high      ,       00              
                SUB             value           ,       01                              ; reduce if down to zero
                RETURN  Z                                                               ; finished if down to zero
                CALL    sum_to_value                                    ; recursively call of subroutine
                RETURN                                                                  ; finished !
                
                

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.