Skip to content

Commit

Permalink
Allow decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
ibara committed Apr 10, 2021
1 parent 2580ffc commit e1eaf75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ capital letters.

Numbers
-------
All numbers must be in hex and must end with an `h`. If a hex
number begins with `a-f`, it must be prefixed with `0`. This is not
too dissimilar from other CP/M assemblers.
Numbers may be in decimal or hex.

Hex numbers must end with an `h`. If a hex number begins with
`a-f`, it must be prefixed with `0`. This is not too dissimilar
compared to other CP/M assemblers.

Strings
-------
Expand Down
48 changes: 27 additions & 21 deletions source/a80/i80.d
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,8 @@ static void equ()
if (lab.empty)
err("must have a label in equ statement");

if (a1[a1.length - 1] != 'h')
err("number must end with 'h'");
auto a = to!ushort(chop(a1), 16);
auto a = numcheck();

if (pass == 1)
addsym(lab, a);
}
Expand All @@ -1178,9 +1177,8 @@ static void db()
{
argcheck(!a1.empty && a2.empty);
if (isDigit(a1[0])) {
if (a1[a1.length - 1] != 'h')
err("number must end with 'h'");
passAct(1, to!ubyte(chop(a1), 16));
auto a = numcheck();
passAct(1, a);
} else {
if (pass == 1) {
if (!lab.empty)
Expand Down Expand Up @@ -1215,21 +1213,17 @@ static void dw()
static void ds()
{
argcheck(!a1.empty && a2.empty);
if (isDigit(a1[0])) {
if (a1[a1.length - 1] != 'h')
err("number must end with 'h'");
}

if (pass == 1) {
if (!lab.empty)
addsym(lab, addr);
} else {
auto a = to!short(chop(a1), 16);
auto a = numcheck();
for (size_t i = 0; i < a; i++)
output ~= cast(ubyte)0;
}

addr += to!ushort(chop(a1), 16);
addr += numcheck();
}

/**
Expand All @@ -1239,10 +1233,8 @@ static void org()
{
argcheck(lab.empty && !a1.empty && a2.empty);
if (isDigit(a1[0])) {
if (a1[a1.length - 1] != 'h')
err("number must end with 'h'");
if (pass == 1)
addr = to!ushort(chop(a1), 16);
addr = numcheck();
} else {
err("org must take a number");
}
Expand Down Expand Up @@ -1329,9 +1321,10 @@ static void imm(int type)
check = a1;

if (isDigit(check[0])) {
if (check[check.length - 1] != 'h')
err("number must end with 'h'");
dig = to!ushort(chop(check), 16);
if (check[check.length - 1] == 'h')
dig = to!ushort(chop(check), 16);
else
dig = to!ushort(check, 10);
} else {
for (size_t i = 0; i < stab.length; i++) {
if (check == stab[i].name) {
Expand Down Expand Up @@ -1362,9 +1355,7 @@ static void a16()
bool found = false;

if (isDigit(a1[0])) {
if (a1[a1.length - 1] != 'h')
err("number must end with 'h'");
dig = to!ushort(chop(a1), 16);
dig = numcheck();
} else {
for (size_t i = 0; i < stab.length; i++) {
if (a1 == stab[i].name) {
Expand Down Expand Up @@ -1402,3 +1393,18 @@ static void argcheck(bool passed)
if (passed == false)
err("arguments not correct for opcode");
}

/**
* Check if a number is decimal or hex.
*/
static ushort numcheck()
{
ushort num;

if (a1[a1.length - 1] == 'h')
num = to!ushort(chop(a1), 16);
else
num = to!ushort(a1, 10);

return num;
}

0 comments on commit e1eaf75

Please sign in to comment.