Print registers and execute basic mov instructions
This commit is contained in:
parent
32ddb518e9
commit
7e74d1e9a2
24
execution.odin
Normal file
24
execution.odin
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
sim8086.odin
24
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[:])
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user