41 lines
1.4 KiB
Odin
41 lines
1.4 KiB
Odin
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 {
|
|
// val := registers[reg_id.id].value.full
|
|
#partial switch val in inst.src {
|
|
case Immediate:
|
|
if val.size == .Signed16 {
|
|
registers[reg_id.id].value.full = (u16)(val.value)
|
|
} else {
|
|
value := u8(val.value & 0xFF)
|
|
if reg_id.access == .Low {
|
|
registers[reg_id.id].value.low = value
|
|
} else {
|
|
registers[reg_id.id].value.high = value
|
|
}
|
|
}
|
|
case RegisterId:
|
|
switch val.access {
|
|
case .Low, .High:
|
|
value := val.access == .Low ? registers[val.id].value.low : registers[val.id].value.high
|
|
if reg_id.access == .Low {
|
|
registers[reg_id.id].value.low = value
|
|
} else {
|
|
registers[reg_id.id].value.high = value
|
|
}
|
|
case .Full:
|
|
registers[reg_id.id].value.full = registers[val.id].value.full
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|