Odin port
This commit is contained in:
parent
021c4573fa
commit
0e4aebff13
62
decoder8086.odin
Normal file
62
decoder8086.odin
Normal file
@ -0,0 +1,62 @@
|
||||
package decoder_8086
|
||||
|
||||
import "core:os"
|
||||
import "core:fmt"
|
||||
|
||||
Register :: struct {
|
||||
fullname: string,
|
||||
bytename: string,
|
||||
value: struct #raw_union {
|
||||
using _: struct {
|
||||
low, high: byte,
|
||||
},
|
||||
full: u16,
|
||||
},
|
||||
code: u8,
|
||||
}
|
||||
|
||||
registers := [8]Register {
|
||||
{fullname = "ax", bytename = "al", code = 0b000},
|
||||
{fullname = "cx", bytename = "cl", code = 0b001},
|
||||
{fullname = "dx", bytename = "dl", code = 0b010},
|
||||
{fullname = "bx", bytename = "bl", code = 0b011},
|
||||
{fullname = "sp", bytename = "ah", code = 0b100},
|
||||
{fullname = "bp", bytename = "ch", code = 0b101},
|
||||
{fullname = "si", bytename = "dh", code = 0b110},
|
||||
{fullname = "di", bytename = "bh", code = 0b111},
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
ax := registers[0]
|
||||
ax.value.full = 52428
|
||||
f,err := os.open("./asm_files/01-01-38.bin")
|
||||
if err != os.ERROR_NONE {
|
||||
os.exit(1)
|
||||
}
|
||||
defer os.close(f)
|
||||
|
||||
data := make([]u8, 256)
|
||||
bytes_read, err2 := os.read(f, data)
|
||||
if err2 != nil {
|
||||
// ...
|
||||
os.exit(1)
|
||||
}
|
||||
// mov cx, bx ; mov 001, 011
|
||||
// mov dx, bx
|
||||
|
||||
read_next := false
|
||||
for b in data {
|
||||
if read_next {
|
||||
mod := (b & 0b11000000) >> 6
|
||||
reg := (b & 0b00111000) >> 3
|
||||
rm := b & 0b00000111
|
||||
fmt.printfln("mov %s, %s", registers[rm].fullname, registers[reg].fullname)
|
||||
read_next = false
|
||||
continue
|
||||
}
|
||||
if b == 0b10001001 {
|
||||
read_next = true
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user