aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-21 17:42:51 +0000
committerGravatar Peter McGoron 2023-02-21 17:42:51 +0000
commit6e0d124efd41b9c6df384a4c41343a65ade7fa87 (patch)
tree86eac3ac8328d1d59c7100fec8a6be0dbfe18815
parenttest many jumps (diff)
add data parsing
-rw-r--r--asm/creole.py19
-rw-r--r--asm/test.py6
2 files changed, 22 insertions, 3 deletions
diff --git a/asm/creole.py b/asm/creole.py
index a614701..e323432 100644
--- a/asm/creole.py
+++ b/asm/creole.py
@@ -72,10 +72,10 @@ class Argument:
class StringArgument(Argument):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
- def __bytes__(self):
+ def __call__(self):
b = bytes()
for v in self.val:
- b = b + Argument(ArgType.IMM, v)()
+ b = b + Argument(ArgType.IMM, int(v, base=16))()
return b
class LabelArgument(Argument):
@@ -350,6 +350,19 @@ class Line:
class InstructionNotFoundException(Exception):
pass
+
+def _term_sep(s):
+ """ Split up the arguments of an instruction.
+ OP arg1 arg2 [data,data,data,...]
+ """
+
+ s = s.strip()
+ s_data = s.split('[')
+ if len(s_data) == 2:
+ return s_data[0].split() + [s_data[1].rstrip('] \t\n\r\v').split(',')]
+ else:
+ return s.split()
+
class Program:
def _asm_push_line(self, ins, args):
l = Line(ins, args)
@@ -361,7 +374,7 @@ class Program:
:param line: String containing the line.
:raises InstructionNotFoundException:
"""
- line = line.strip().split()
+ line = _term_sep(line)
line[0] = line[0].casefold()
if line[0][0] == '.':
self.asm.append(line[0])
diff --git a/asm/test.py b/asm/test.py
index 4ab05e6..e49d46d 100644
--- a/asm/test.py
+++ b/asm/test.py
@@ -433,6 +433,12 @@ class ProgramTest(unittest.TestCase):
self.range_test(0x7FFFF00, 0x8000000, sgn=True)
self.range_test(-100, 0, sgn=True)
+class DataTest(unittest.TestCase):
+ def test_parse_db(self):
+ p = Program()
+ p.parse_asm_line("db d0 [4d2,1234,0,5]")
+ self.assertEqual(p(), b'\x0b\xc0\x80\xe0\x93\x92\xf0\x81\x88\xb4\xc0\x80\xc0\x85\x00')
+
class SCEnv(ffi.Environment):
def syscall(self, s):
self.s = s.value
an title='2021-07-26 19:49:48 -0400'>2021-07-26typosGravatar John Cowan 1-1/+1 2021-07-26paired mutatorsGravatar John Cowan 1-43/+68 2021-07-26exceptionsGravatar John Cowan 1-1/+15 2021-07-26new exampleGravatar John Cowan 1-1/+4 2021-07-26updatesGravatar John Cowan 1-2/+4 2021-07-26dtd always first argumentGravatar John Cowan 1-9/+9 2021-07-26DTO to DTDGravatar John Cowan 1-55/+52 2021-07-26typoGravatar John Cowan 1-1/+1 2021-07-26switching to explicit dtosGravatar John Cowan 1-88/+102 2021-07-26errorsGravatar John Cowan 1-1/+4 2021-07-26more MN-W reviewGravatar John Cowan 1-5/+5 2021-07-26update preview linkGravatar John Cowan 1-1/+1 2021-07-26MN-W reviewGravatar John Cowan 1-6/+6 2021-07-26paired mutatorsGravatar John Cowan 1-43/+68 2021-07-25exceptionsGravatar John Cowan 1-1/+15 2021-07-25new exampleGravatar John Cowan 1-1/+4 2021-07-25updatesGravatar John Cowan 1-2/+4 2021-07-24dtd always first argumentGravatar John Cowan 1-9/+9 2021-07-23DTO to DTDGravatar John Cowan 1-55/+52 2021-07-22typoGravatar John Cowan 1-1/+1 2021-07-22switching to explicit dtosGravatar John Cowan 1-88/+102 2021-07-22errorsGravatar John Cowan 1-1/+4 2021-07-22more MN-W reviewGravatar John Cowan 1-5/+5 2021-07-20update preview linkGravatar John Cowan 1-1/+1 2021-07-20MN-W reviewGravatar John Cowan 1-6/+6 2021-07-18Fix typo.Gravatar Arthur A. Gleckler 2-4/+4 2021-07-18Add <p> around abstract.Gravatar Arthur A. Gleckler 1-2/+2 2021-07-18Publish first draft.draft-1Gravatar Arthur A. Gleckler 3-0/+114 2021-07-18Ignore trailing whitespace.Gravatar Arthur A. Gleckler 11-129/+129 2021-07-18Ignore "Dictionaries.log".Gravatar Arthur A. Gleckler 1-1/+2 2021-07-18Fix errors reported by W3C HTML Validator.Gravatar Arthur A. Gleckler 1-27/+27 2021-07-18Eliminate unnecessary redirect by using TLS/SSL.Gravatar Arthur A. Gleckler 1-1/+1