Skip to content

Chapter 3.4 conversion to i8 for Branch #29

Description

@dariandzirko

In cpu.rs

fn branch(&mut self, condition: bool) {
        if condition {
            let jump: i8 = self.mem_read(self.program_counter) as i8;
            let jump_addr = self
                .program_counter
                .wrapping_add(1)
                .wrapping_add(jump as u16);

If I change jump to u16 I get an extremely incorrect result immediately resulting in a BRK command run. The negative flag isn't set and it is immediately changed back to u16 later in the wrapping add. Any idea about this? Is there something in the documentation I am missing where this should a signed and then unsigned add?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions