Skip to content

Add assembler module for machine code compilation #15

@Flu

Description

@Flu

Background

The emulator in its current state is incomplete, because there are some constraints that we didn't take into account when we first made the emulator. For example, the LDI instruction technically can only load values into registers 16 through 31, because of the way the binary representation of the instruction works. This isn't taken into account by the current emulator because there is currently no good place for us to check that. It isn't parser's job to check that LDI can load in R15 or not, since the grammar doesn't specify that it couldn't. Neither is the emulator's job, because it must assume that all instructions are correct to do its job. Label resolving shouldn't be in the emulator either. So then where should we put them? Technically, both of those are the job of the assembler. The assembler should make sure that the syntactically correct program we gave to it is semantically correct and fulfills those requirements.

Goal

The goal of the emulator program as a whole is for it to function in two possible ways:

  • It takes in an assembly file, assembles it into machine code, passes it on to the emulator, which interprets it and executes it.
  • It can take in the machine code directly, in which case we bypass the parser and the assembler, and it should go directly to the emulator.

Requirements

The module should:

  1. Check that there are no duplicate labels defined or that a label was used that wasn't defined
  2. Check that the semantics of the instruction are respected. For example, LDI R15, 0x00 is not a valid instruction because LDI can only load registers R16-R31. This is not a parsing error, this would be an assembler error.
  3. Check how much each instruction takes up in the program memory (usually 2 bytes, ocasionally 3 or 4 for AVR).
  4. Contruct the program memory and return it in a ProgramMemory object that can either go to the emulator or exported.
  5. Separate the Instruction datatype for the Parser and the Emulator. This means that the we will have two types called Instruction. One is going to be used by the parser to return the instructions it finds. The other is the data type that the Emulator will use after interpreting the binary code. These need to be separated

Metadata

Metadata

Assignees

Labels

assemblerConcerning the assembleremulator internalMods on the internal emulator API or functionalityenhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions