commit 5c65abd0607ea694a65fee66a05283d1021ea35e from: Benjamin Stürz date: Tue Jun 11 02:19:28 2024 UTC fix M instructions commit - 556cf3fcc326710d1d7db9f8340568349fe04108 commit + 5c65abd0607ea694a65fee66a05283d1021ea35e blob - 4f4a708a8a59aae419e3804e0e2ad6537725d0cb blob + c330c80c729c9585f20ce981f16a40a4d8bcb6b8 --- examples/test.c +++ examples/test.c @@ -21,6 +21,11 @@ inline static void *sys_brk (void *ptr) return a0; } +unsigned mul(unsigned a, unsigned b) +{ + return a / b; +} + int main (int argc, char *argv[]) { FILE *in, *out; int ch, *ptr; @@ -52,5 +57,7 @@ int main (int argc, char *argv[]) { fclose (in); + printf ("Result: %u\n", mul (3, 2)); + return 0; } blob - 1097223b6bee26ebd2770d2554da81f7992465a1 blob + 7f88c1790ad9c4ed9776a28bab20fdbea8ae19be --- src/cpu.c +++ src/cpu.c @@ -422,19 +422,19 @@ void cpu_exec (u32 instr) c = extend (a * b); alu ("mulw"); break; - case 0b000001'001: // divw + case 0b000001'100: // divw c = extend (b != 0 ? (i32)a / (i32)b : -1); alu ("divw"); break; - case 0b000001'010: // divuw + case 0b000001'101: // divuw c = extend (b != 0 ? (u32)a / (u32)b : -1); alu ("divuw"); break; - case 0b000001'011: // remw + case 0b000001'110: // remw c = extend (b != 0 ? (i32)a % (i32)b : (i32)a); alu ("divw"); break; - case 0b000001'100: // remuw + case 0b000001'111: // remuw c = extend (b != 0 ? (u32)a % (u32)b : (u32)b); alu ("divuw"); break;