uncrustified example programs

master
Anton Lydike 3 years ago
parent 31e2b25059
commit 8560bf6d5b

@ -1,4 +1,3 @@
#define TEXT_IO_ADDR 0xff0000 #define TEXT_IO_ADDR 0xff0000
#define TEXT_IO_BUFLEN 64 #define TEXT_IO_BUFLEN 64
@ -8,9 +7,11 @@ char* itoa (int value, char* str, int base);
char text[48] = "the number is "; char text[48] = "the number is ";
int main() { int main()
{
dbgln("main", 4); dbgln("main", 4);
int a = 144; int a = 144;
while (1) { while (1) {
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) { for (int j = 0; j < 10000; j++) {
@ -64,6 +65,7 @@ char* itoa (int value, char* str, int base)
int digits = 0; int digits = 0;
int num = 0; int num = 0;
// reverse number // reverse number
do { do {
num = num * base; num = num * base;
@ -78,13 +80,13 @@ char* itoa (int value, char* str, int base)
value = value / base; value = value / base;
*str++ = alpha[num]; *str++ = alpha[num];
digits--; digits--;
} }while (digits > 0);
while (digits > 0);
return str; return str;
} }
void _start() { void _start()
{
__asm__ ( __asm__ (
".option push\n" ".option push\n"
".option norelax\n" ".option norelax\n"
@ -94,6 +96,7 @@ void _start() {
dbgln("start", 5); dbgln("start", 5);
int exit_code = main(); int exit_code = main();
dbgln("end", 3); dbgln("end", 3);
__asm__ ( __asm__ (

@ -1,4 +1,3 @@
#define TEXT_IO_ADDR 0xff0000 #define TEXT_IO_ADDR 0xff0000
#define TEXT_IO_BUFLEN 64 #define TEXT_IO_BUFLEN 64
@ -7,7 +6,8 @@ char* itoa (int value, char* str, int base);
int thread(void* args); int thread(void* args);
int main() { int main()
{
dbgln("main", 4); dbgln("main", 4);
int arg = 144; int arg = 144;
@ -19,7 +19,8 @@ int main() {
"ecall" :: "r"(thread), "r"(&arg) "ecall" :: "r"(thread), "r"(&arg)
); );
while (arg == 144) {} while (arg == 144) {
}
__asm__ ("ebreak"); __asm__ ("ebreak");
return 0; return 0;
@ -30,6 +31,7 @@ int thread(void* args)
int arg = *((int*) args); int arg = *((int*) args);
char buff[32] = "the magic number is: "; char buff[32] = "the magic number is: ";
char* end = itoa(arg, &buff[21], 10); char* end = itoa(arg, &buff[21], 10);
dbgln(buff, (int) (end - buff)); dbgln(buff, (int) (end - buff));
// *((int*) args) = 0; // *((int*) args) = 0;
@ -75,6 +77,7 @@ char* itoa (int value, char* str, int base)
int digits = 0; int digits = 0;
int num = 0; int num = 0;
// reverse number // reverse number
do { do {
num = num * base; num = num * base;
@ -89,13 +92,13 @@ char* itoa (int value, char* str, int base)
value = value / base; value = value / base;
*str++ = alpha[num]; *str++ = alpha[num];
digits--; digits--;
} }while (digits > 0);
while (digits > 0);
return str; return str;
} }
void _start() { void _start()
{
__asm__ ( __asm__ (
".option push\n" ".option push\n"
".option norelax\n" ".option norelax\n"
@ -105,6 +108,7 @@ void _start() {
dbgln("start", 5); dbgln("start", 5);
int exit_code = main(); int exit_code = main();
dbgln("end", 3); dbgln("end", 3);
__asm__ ( __asm__ (

Loading…
Cancel
Save