Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LOADU8 #156

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,16 @@ where
// The array index of the word for the byte to read from
let index_of_read = index_of_byte(read_addr.into());
// The byte from the read cell.
let cell_byte = cell[index_of_read];
let cell_byte: u8 = cell[index_of_read];

let write_addr = (state.cpu().fp as i32 + ops.a()) as u32;
// The address, converted to a multiple of 4.
let write_addr_index = addr_of_word(write_addr);

// The Word to write, with one byte overwritten to the read byte
let cell_to_write = Word::zero_extend_byte(cell_byte);

state
.mem_mut()
.write(clk, write_addr_index, cell_to_write, true);
.write(clk, write_addr_index, Word::from_u8(cell_byte), true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm....I was assuming little endian format and that's why the byte is written to [0] with zero_extend_byte but maybe it should be at the end like from_u8?

The C test doesn't work either way probably because there are more bugs. But write is working so perhaps I should indeed use from_u8. If so we should remove zero_extend_byte.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also then I should change sign_extend_byte. I pushed a commit. Test still not working.

state.cpu_mut().pc += 1;
state.cpu_mut().push_op(Operation::LoadU8, opcode, ops);
}
Expand Down
Loading