From 7e74d1e9a213e786aef6412663cf3bf87260a821 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sat, 15 Mar 2025 22:28:54 +0700 Subject: [PATCH] Print registers and execute basic mov instructions --- execution.odin | 24 ++++++++++++++++++++++++ sim8086.odin | 24 ++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 execution.odin diff --git a/execution.odin b/execution.odin new file mode 100644 index 0000000..70b38a8 --- /dev/null +++ b/execution.odin @@ -0,0 +1,24 @@ +package sim_8086 + +import "core:os" +import "core:fmt" +import "core:math" +import "core:strings" + +execute_instruction :: proc(inst: Instruction) { + #partial switch inst.opname { + case .MOV: + if reg_id,ok := inst.dst.(RegisterId); ok { + #partial switch val in inst.src { + case Immediate8: + registers[reg_id].value.low = (u8)(val) + case ImmediateU8: + registers[reg_id].value.low = (u8)(val) + case Immediate16: + registers[reg_id].value.low = (u8)(val) + case RegisterId: + registers[reg_id].value.full = registers[val].value.full + } + } + } +} diff --git a/sim8086.odin b/sim8086.odin index 49bddfe..a8896f9 100644 --- a/sim8086.odin +++ b/sim8086.odin @@ -76,10 +76,6 @@ main :: proc() { os.exit(1) } - if false { - os.exit(0) - } - // asdf :u16 = 0b00000110_11011101 // asdf2 :i16 = (i16)(asdf) // fmt.printfln("%d", asdf2) @@ -89,10 +85,22 @@ main :: proc() { instructions_list := make([dynamic]Instruction, 0, 512) decode_data(&instructions_list, data[:], bytes_read) - // for inst in instructions_list { - // fmt.println(inst) - // } + + for inst in instructions_list { + execute_instruction(inst) + } + if true { - print_instructions_stdout(instructions_list[:]) + for reg in registers { + full := fmt.aprintf("%s (%s): %d ", reg.fullname, reg.bytename, reg.value.full) + // hex := fmt.aprintf("%s %*[1]s 0x%x ", full, 25 - len(full), "|", reg.value.full) + hex := fmt.aprintf("0x%x ", reg.value.full) + fmt.printf("%s %*[1]s %s %*[4]s %08b %08b", + full, 20 - len(full), "|", hex, 10 - len(hex), "|", reg.value.high, reg.value.low) + fmt.println() + } + } + if true { + // print_instructions_stdout(instructions_list[:]) } }