Conversation
Read memory from a file path
* can process add instruction * modify register access * add methods for getting and setting register values * add tests
Feature: add instructions related to registers
* creates file for trap codes and convertion from u16 * add getc instr * add new trap errors
Feature: memory operations
Feature: Traps
… feature/run_programs merge local repo
Feature: run programs
Please provide a more detailed description of the PR. It's important to provide guidance to reviewers. For example:
|
| // collect file to execute | ||
| let args: Vec<String> = env::args().collect(); | ||
| if args.len() != 2 { | ||
| println!("make run FILEPATH=<path/to/file>"); |
There was a problem hiding this comment.
As a UX improvement, I would add something to notify the user how the VM is meant to be used. For example, instead of printing:
make run FILEPATH=<path/to/file>It can print something like:
Usage:
make run FILEPATH=<path/to/file>| /// Main execution loop | ||
| /// | ||
| /// Read instruction, increments the PC, execute the instruction | ||
| /// Repeat this while the machine is in a state of running |
There was a problem hiding this comment.
Please clarify this. I would involve the running field because it's public so the user knows about this field.
There was a problem hiding this comment.
Nice!, the members of the VM being public was an error I didn't update.
The comment's clarification and the remove of pub are here, b37e99d
| /// Get value stored in the register requested | ||
| /// | ||
| /// If register is not 0 to 7, an Error is returned |
There was a problem hiding this comment.
I would include register_index to document how the function argument affects the function logic. For example:
| /// Get value stored in the register requested | |
| /// | |
| /// If register is not 0 to 7, an Error is returned | |
| /// Get value stored in the register requested in `register_index` | |
| /// | |
| /// If `register_index` is outside of the range from 0 to 7, an Error is returned |
| /// Set a value in the register requested | ||
| /// | ||
| /// If register is not 0 to 7, an Error is returned |
There was a problem hiding this comment.
I would include register_index and value to document how the function arguments affect the function logic.
| /// Update flags based on the content of the register requested | ||
| /// | ||
| /// If register is not 0 to 7, an Error is returned |
There was a problem hiding this comment.
I would include register to document how the function argument affects the function logic. Also, if in the other functions the argument is called register_index why it's called different here?
| Ok(()) | ||
| } | ||
|
|
||
| /// Based on the opcode from the instruction bits, executes the corresponding procedure |
There was a problem hiding this comment.
I would include instr to document how the function argument affects the function logic.
| Opcode::And => self.and(instr), | ||
| Opcode::Ldr => self.ldr(instr), | ||
| Opcode::Str => self.str(instr), | ||
| Opcode::Rti => Err(VMError::InvalidOpcode), |
There was a problem hiding this comment.
Add a short comment on why this opcode is invalid
| Opcode::Ldi => self.ldi(instr), | ||
| Opcode::Sti => self.sti(instr), | ||
| Opcode::Jmp => self.jmp(instr), | ||
| Opcode::Res => Err(VMError::InvalidOpcode), |
There was a problem hiding this comment.
Add a short comment on why this opcode is invalid
| /// Stores in DR the addition between SR1 and SR2 or SR1 and imm5 sign extended | ||
| /// Bit 5 if it is 1, then is read as a imm5 |
There was a problem hiding this comment.
Bit 5, SR2 and imm5 doesn't seem to be related according to this documentation. Please refactor this so that the relationship is explicit. For example:
| /// Stores in DR the addition between SR1 and SR2 or SR1 and imm5 sign extended | |
| /// Bit 5 if it is 1, then is read as a imm5 | |
| /// If Bit 5 is 0, stores in DR the addition between SR1 and SR2. | |
| /// If Bit 5 is 1, stores in DR the addition between SR1 and imm5. |
| /// Stores in DR the and bitwise between SR1 and SR2 or SR1 and imm5 sign extended | ||
| /// Bit 5 if it is 1, then is read as a imm5 |
There was a problem hiding this comment.
Bit 5, SR2 and imm5 doesn't seem to be related according to this documentation. Please refactor this so that the relationship is explicit.
| /// In bit 11 is to jump if is negative | ||
| /// In bit 10 is to jump if is zero | ||
| /// In bit 9 is to jump if positive | ||
| /// | ||
| /// Stores in PC the addition of the PC and the sign extended PCoffset9 only if the condition flag | ||
| /// meets any of the bits that are 1 |
Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.