user3885166
user3885166

Reputation: 215

Assembler for Marie

I want to write an assembler for marie, however I am stuck right in the beginning. My machine code has to have following format: FFFF 'first address' 'last addres' '... commands'

Let's say we have a code like this:

LOAD 104
ADD 105
STORE 106
HALT
HEX 23
HEX FFE9
DEC 0

Now, there is no way to tell which address do we start at, so should I just use 100 all the time, or does it sometimes change?

Now, for last address, is it simply 100+(number of commands)?

Thanks in advance

Upvotes: 0

Views: 1118

Answers (1)

Ruud Helderman
Ruud Helderman

Reputation: 11018

Real-life assemblers use a meta-instruction (often called ORG which is short for 'origin', e.g. ORG 100) to instruct the assembler on what address to start (or resume, when placed somewhere in the middle of the program). Of course, feel free to solve it in another way (hard-coded; command-line parameter).

Exactly what the correct address is for a program written for MARIE, depends entirely on the runtime system (on real computers, the OS; in your case, a simulator). I see code samples starting from 100, so that would make sense. Maybe addresses lower than 100 are reserved for the runtime system, who knows.

From there, the assembler automatically increases the address with every instruction. With MARIE, I suppose that's straightforward (just add one); in real-life processors, different instructions typically have different sizes.

For the rest, if you know how to convert assembly language to machine code by hand, then automating that process should be straightforward.

Upvotes: 2

Related Questions