Add .LOOP instruction, dump memory to disk with cli arg
This commit is contained in:
parent
fafb440891
commit
85a8172923
@ -111,6 +111,9 @@ execute_instruction :: proc(cpu: ^Cpu, inst: Instruction) {
|
||||
case .JP, .JPE: jump = cpu.flags[.PF]
|
||||
case .JB, .JNAE: jump = cpu.flags[.CF]
|
||||
|
||||
case .LOOP:
|
||||
cpu.registers[.cx].full -= 1
|
||||
jump = cpu.registers[.cx].full != 0
|
||||
case .LOOPNZ, .LOOPNE:
|
||||
cpu.registers[.cx].full -= 1
|
||||
// According to this resource, the loopnz inst does not change any flags
|
||||
|
14
sim8086.odin
14
sim8086.odin
@ -95,4 +95,18 @@ main :: proc() {
|
||||
if what_to_print == "instructions" || what_to_print == "all" {
|
||||
print_instructions_stdout(instructions_list[:])
|
||||
}
|
||||
if len(os.args) > 3 && os.args[3] == "dump" {
|
||||
f2,open_err := os.open("./listing-54.data", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if open_err == nil {
|
||||
bytes_written,write_err := os.write(f2, cpu.memory[:])
|
||||
if write_err == nil {
|
||||
fmt.println("Dumpped", bytes_written, "to disk: listing-54.data")
|
||||
} else {
|
||||
fmt.println("Error2:", write_err)
|
||||
}
|
||||
} else {
|
||||
fmt.println("Error1:", open_err)
|
||||
}
|
||||
defer os.close(f)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user