Skip to content

Add branches and jumps #8

@kevinamccorvon

Description

@kevinamccorvon

After ALU and memory work need control flow so loops and function calls work. Conditional branches (BEQ/BNE/BLT/BGE/BLTU/BGEU) evaluate condition and if true set PC to PC + offset otherwise PC += 4. Unconditional jumps JAL saves PC+4 to rd then sets PC to PC + offset, JALR saves PC+4 to rd then sets PC to (rs1 + offset) & ~1 (clear LSB per spec).
Need to update execution loop to handle PC changes from branches/jumps, validate targets are aligned to 4-byte boundaries, maybe add max cycle count to catch infinite loops in tests. Test branches taken vs not taken, signed vs unsigned comparisons with negative numbers, forward and backward jumps, function calls with JAL and returns with JALR, simple loops, nested calls. If this works fibonacci and factorial examples should run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions