refactoring fixes
This commit is contained in:
38
runtime/io/vx_io.c
Normal file
38
runtime/io/vx_io.c
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
#include "vx_io.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void vx_print_hex(unsigned f)
|
||||
{
|
||||
// vx_print_str(hextoa[f]);
|
||||
if (f < 16)
|
||||
{
|
||||
vx_print_str(hextoa[f]);
|
||||
return;
|
||||
}
|
||||
int temp;
|
||||
int sf = 32;
|
||||
bool start = false;
|
||||
do
|
||||
{
|
||||
temp = (f >> (sf - 4)) & 0xf;
|
||||
if (temp != 0) start = true;
|
||||
if (start) vx_print_str(hextoa[temp]);
|
||||
sf -= 4;
|
||||
} while(sf > 0);
|
||||
}
|
||||
|
||||
|
||||
void vx_printf(const char * c, unsigned f)
|
||||
{
|
||||
vx_print_str(c);
|
||||
vx_print_hex(f);
|
||||
vx_print_str("\n");
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
20
runtime/io/vx_io.h
Normal file
20
runtime/io/vx_io.h
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static char * hextoa[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
||||
void vx_print_hex(unsigned);
|
||||
void vx_printf(const char *, unsigned);
|
||||
|
||||
void vx_print_str(const char *);
|
||||
void vx_printc(unsigned, char c);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
33
runtime/io/vx_io.s
Normal file
33
runtime/io/vx_io.s
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
.type vx_print_str, @function
|
||||
.global vx_print_str
|
||||
vx_print_str:
|
||||
addi sp, sp, -12
|
||||
sw ra, 0(sp)
|
||||
sw a1, 4(sp)
|
||||
bl:
|
||||
lbu a1,0(a0)
|
||||
beqz a1,be
|
||||
jal vx_printc
|
||||
addi a0, a0, 1
|
||||
j bl
|
||||
be:
|
||||
lw ra, 0(sp)
|
||||
lw a1, 4(sp)
|
||||
addi sp, sp, 12
|
||||
ret
|
||||
|
||||
|
||||
.type vx_printc, @function
|
||||
.global vx_printc
|
||||
vx_printc:
|
||||
la t0, print_addr
|
||||
lw t0, 0(t0)
|
||||
sw a1, 0(t0)
|
||||
ret
|
||||
|
||||
.section .data
|
||||
print_addr:
|
||||
.word 0x00010000
|
||||
|
||||
Reference in New Issue
Block a user