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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [sw/] [code/] [kcpsm/] [stack_test/] [SumValue.psm] - Blame information for rev 67

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

Line No. Rev Author Line
1 2 ameziti
; this programm calculate the sum of the "value" 16bit.
2
; value = 5; total = 5 + 3 + 2 + 1 = 15
3
; the result is 16bit outputed
4
                CONSTANT        WAVEFORM_PORT, 02
5
                CONSTANT        COUNTER_PORT, 04
6
 
7
                NAMEREG s0, total_low
8
                NAMEREG s1, total_high
9
                NAMEREG s8, value
10
 
11
start:
12
                LOAD    value           ,       1F                              ; find sum of all values to 31
13
                LOAD    total_low       ,       00                              ; clear 16-bit total
14
                LOAD    total_high      ,       00                              ;
15
 
16
                CALL    sum_to_value                                    ; calculate sum of all numbers up to value
17
 
18
                OUTPUT  total_high      ,       COUNTER_PORT    ; Result will be 496 (01F0)hex
19
                OUTPUT  total_low       ,       WAVEFORM_PORT   ;
20
 
21
end:
22
                JUMP    end
23
                ;
24
 
25
                ; Subroutine called recursively
26
sum_to_value:
27
                ADD             total_low       ,       value                   ; perform 16-bit addition
28
                ADDCY   total_high      ,       00
29
                SUB             value           ,       01                              ; reduce if down to zero
30
                RETURN  Z                                                               ; finished if down to zero
31
                CALL    sum_to_value                                    ; recursively call of subroutine
32
                RETURN                                                                  ; finished !
33
 
34
 

powered by: WebSVN 2.1.0

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