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

Subversion Repositories forwardcom

[/] [forwardcom/] [libraries/] [print_hexadecimal_light.as] - Blame information for rev 139

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

Line No. Rev Author Line
1 97 Agner
/***************************  print_hexadecimal_light.as **********************
2
* Author:        Agner Fog
3
* date created:  2021-05-16
4
* Last modified: 2021-05-16
5
* Version:       1.11
6
* Project:       ForwardCom library libc_light.li
7
* Description:   puts: print a string to stdout. Does not append linefeed
8
* This version is for CPUs with limited capabilities
9
* C declaration: void print_hexadecimal(uint64_t h);
10
*
11
* Copyright 2021 GNU General Public License http://www.gnu.org/licenses
12
******************************************************************************/
13
 
14
code section execute align = 4                   // code section
15
 
16
// Print a hexadecimal number to stdout
17
 
18
_print_hexadecimal function public reguse=3,0
19
 
20
// save r2-r3
21
int64 sp -= 2*8
22
int64 [sp]      = r2
23
int64 [sp+8]    = r3
24
 
25
int64 r1 = bitscan(r0, 1)              // find number of bits
26
uint32 r1 >>= 2
27
uint32 r1++                            // number of digits to print
28
if (int r1 > 8) {                      // must use 64 bits
29
    int r2 = 16 - r1                   // number of digits to skip
30
    int r2 <<= 2                       // number of bits to skip
31
    uint64 r0 <<= r2                   // remove leading zeroes
32
    for (int ; r1 > 0; r1--) {         // loop r1 times
33
        uint64 r0 = rotate(r0, 4)      // get digit into low position
34
        int r2 = r0 & 0xF              // get digit
35
        int r2 += '0'                  // convert to ASCII
36
        int r3 = r2 > '9'              // digit is A - F
37
        int r2 = r3 ? r2 + 7 : r2      // add 7 to get letter
38
        int8 output(r2, r2, 10);       // output digit
39
    }
40
}
41
else {                                 // use 32 bits. CPU may not support 64 bits
42
    int r2 = 8 - r1                    // number of digits to skip
43
    int r2 <<= 2                       // number of bits to skip
44
    uint32 r0 <<= r2                   // remove leading zeroes
45
    for (int ; r1 > 0; r1--) {         // loop r1 times
46
        uint32 r0 = rotate(r0, 4)      // get digit into low position
47
        int r2 = r0 & 0xF              // get digit
48
        int r2 += '0'                  // convert to ASCII
49
        int r3 = r2 > '9'              // digit is A - F
50
        int r2 = r3 ? r2 + 7 : r2      // add 7 to get letter
51
        int8 output(r2, r2, 10);       // output digit
52
    }
53
}
54
 
55
// restore r2-r3
56
int64 r2 = [sp]
57
int64 r3 = [sp+8]
58
int64 sp += 2*8
59
 
60
return
61
_print_hexadecimal end
62
 
63
 
64
code end

powered by: WebSVN 2.1.0

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