~grimmware/lc3

1529e3e505c18f1c9cb034e4d3e05a23a807072f — glenda 1 year, 2 months ago d4d2999
About to replace all hexnparse with libnparse
1 files changed, 40 insertions(+), 8 deletions(-)

M asm.c
M asm.c => asm.c +40 -8
@@ 165,6 165,29 @@ hexnparselit(int b, char *s)
	return n;
}

u16int
basenparse(int bits, int base, char *s)
{
	u16int n;
	long m;
	m = strtol(s, 0, base);
	n = (u16int) m;
	if(n != m || n >= (1 << bits))
		syntaxerr(smprint("Base %d value %s is too big to be represented in %d bits", base, s, bits));
	return n;
}

u16int
binnparselit(int b, char *s)
{
	return 1;
}

u16int
decnparselit(int b, char *s)
{
	return 1;
}

u16int
hexnparse(int b, char *s)


@@ 175,6 198,21 @@ hexnparse(int b, char *s)
	return hexnparselit(b, s);
}

u16int
litnparse(int b, char *s)
{
	switch(s[0]){
	case 'x':
		return basenparse(b, 16,++s);
	case 'b':
		return basenparse(b, 2, ++s);
	case '#':
		return basenparse(b, 10, ++s);
	default:
		syntaxerr(smprint("Value `%s` is not of a numeric literal format (must start with x/b/#)", s));
	}
	return (u16int) -1;
}

void
validate(Inst *in)


@@ 328,18 366,12 @@ parseline(char *l)
				pc++;
				return -1; // We're done parsing!
			} else if(strcmp(t,".ORIG") == 0){
				//FIXME: only supporting hex for now
				//FIXME: validate that this is the first instruction
				l+=2; //skipping hex number indicator to raw number
				l++;
				gettoken(&t, l);
				// FIXME: replace with hexenparse
				// re-use c
				c = (int) strtol(t, 0, 16);
				c = litnparse(16, t);
				pc = orig = c;
				if(pc != c) { // not a valid u16int
					fprint(2, ".ORIG argument too large\n");
					exits("Orig too big");
				}
				if(debug)
					print("updated origin to %x\n", orig);
				return 0;