Assembler in GNU as syntax, objdump-style disassembly, UCASE$ and LCASE$
The monitor's assembler takes GNU as directives (.org, .equ, .byte, .half, .word, .ascii, .string, .space, .align, .balign ...), # comments, 0x/0b numbers, '\n' constants, . for the current address, << >> ^ ~, %hi/%lo and the FP CSR short forms; the old ORG/DB/EQU/0FFH forms remain as aliases. The disassembler prints lower case and 0x hex as objdump does. The monitor is built with -msave-restore and puts .rodata first, to fit its ROM. BASIC gains UCASE$ and LCASE$. Manual, README and tests updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
25c8286cf2
commit
fa4752fd7a
16 files changed
+7921
-7615
No files matched your search
+27
-7
@@ -80,14 +80,13 @@ static void s_udec(u32 v)
|
||||
s_str(q);
|
||||
}
|
||||
static void s_dec(i32 v) { if (v < 0) { s_ch('-'); v = -v; } s_udec((u32)v); }
|
||||
/* assembler style: 1F0H, 0A200H (a leading 0 when it starts with a letter) */
|
||||
/* GNU style: 0x1f0 (disasm() lower-cases it) */
|
||||
static void s_lit(u32 v)
|
||||
{
|
||||
u8 n = 1;
|
||||
while (n < 8 && v >> (4 * n)) n++;
|
||||
if ((v >> (4 * (n - 1)) & 15) >= 10) s_ch('0');
|
||||
s_str("0X");
|
||||
s_hex(v, n);
|
||||
s_ch('H');
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- disassembler */
|
||||
@@ -129,7 +128,17 @@ static const char *const csrin[8] = { 0, "CSRRW", "CSRRS", "CSRRC", 0, "CSRRWI",
|
||||
|
||||
/* F: registers F0-F31, the rounding mode after the operands unless DYN */
|
||||
static const char *const rmn[8] = { "RNE", "RTZ", "RDN", "RUP", "RMM", 0, 0, "DYN" };
|
||||
static void s_freg(u8 r) { s_ch('F'); s_udec(r); }
|
||||
/* float registers by their ABI names, as objdump shows them: ft0-7 fs0-1
|
||||
fa0-7 fs2-11 ft8-11 */
|
||||
static void s_freg(u8 r)
|
||||
{
|
||||
s_ch('F');
|
||||
if (r < 8) { s_ch('T'); s_udec(r); }
|
||||
else if (r < 10) { s_ch('S'); s_udec(r - 8); }
|
||||
else if (r < 18) { s_ch('A'); s_udec(r - 10); }
|
||||
else if (r < 28) { s_ch('S'); s_udec(r - 16); }
|
||||
else { s_ch('T'); s_udec(r - 20); }
|
||||
}
|
||||
static void s_rm(u8 m) { if (m != 7) { s_c(); s_str(rmn[m]); } }
|
||||
|
||||
/* An F instruction (not FLW/FSW); 0 if it isn't one */
|
||||
@@ -194,8 +203,8 @@ static u8 dis_f(u32 w)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* One instruction at a into line (at lp); returns its length, 4. */
|
||||
static u8 disasm(u32 a)
|
||||
/* One instruction at a into line (at lp), in capitals; returns its length, 4. */
|
||||
static u8 dis_up(u32 a)
|
||||
{
|
||||
u32 w = rd32(a);
|
||||
u8 op = w & 0x7F, rd = w >> 7 & 31, f3 = w >> 12 & 7, rs1 = w >> 15 & 31, rs2 = w >> 20 & 31;
|
||||
@@ -306,10 +315,20 @@ static u8 disasm(u32 a)
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
s_mn("DW"); s_lit(w);
|
||||
s_mn(".WORD"); s_lit(w);
|
||||
return 4;
|
||||
}
|
||||
|
||||
/* One instruction at a into line (at lp), in lower case as GNU tools show
|
||||
it; returns its length, 4. */
|
||||
static u8 disasm(u32 a)
|
||||
{
|
||||
char *s = lp;
|
||||
u8 n = dis_up(a);
|
||||
for (; s < lp; s++) if (*s >= 'A' && *s <= 'Z') *s += 32;
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifndef __riscv
|
||||
#include "asm.c"
|
||||
|
||||
@@ -580,6 +599,7 @@ static u8 get_hex(u32 *v)
|
||||
u8 n = 0;
|
||||
skip_sp();
|
||||
*v = 0;
|
||||
if (cp[0] == '0' && (cp[1] == 'X' || cp[1] == 'x') && is_hex(cp[2])) cp += 2; /* 0x is optional */
|
||||
while (is_hex(*cp)) {
|
||||
*v = *v << 4 | (*cp <= '9' ? *cp - '0' : *cp - 'A' + 10);
|
||||
cp++; n++;
|
||||
|
||||
Reference in new issue
Block a user