How do I write THIS assembler?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I write THIS assembler?

LBSCR
The HACK assembler is hard. How would you assemble "MD=D+1"? Basically, I don't know how to assemble instructions without whitespaces, help me please ;~;
Reply | Threaded
Open this post in threaded view
|

Re: How do I write THIS assembler?

cadet1620
Administrator
What language are you using to write your assembler?

Basically, to parse a C-instruction you need to find the '=' and the ';' so that you can split it into destination, computation, and jump parts:

comp = instruction
dest = empty string
jump = empty string
if comp has a '=':
    i = index of '='
    dest = comp [0..i-1]
    comp = comp [i+1..]
if comp has a ';':
    i = index of ';'
    jump= comp [i+1..]
    comp = comp [0..i-1]

--Mark

Reply | Threaded
Open this post in threaded view
|

Re: How do I write THIS assembler?

LBSCR
Thank you!