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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [sw/] [code/] [pBlaze/] [stack_test/] [sum_value.asm] - Blame information for rev 47

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
                waveform_port           .EQU    0x02
5
                counter_port            .EQU    0x04
6
 
7
                total_low       .EQU   s0
8
                total_high      .EQU   s1
9
                value           .EQU   s8
10
                ;
11
start:
12
                LOAD    value,          0x1F    ; find sum of all values to 1F
13
                LOAD    total_low,      0x00    ; clear 16-bit total
14
                LOAD    total_high,     0x00
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 (1F0 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 value by 1
30
                RETURN  Z                                       ; finished if down to zero
31
                CALL    sum_to_value            ; recursively call of subroutine
32
                RETURN                                          ; definitively finished!

powered by: WebSVN 2.1.0

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