Add more instructions, add segment registers, move types up, read more data

This commit is contained in:
Joseph Ferano 2025-03-07 10:13:49 +07:00
parent c7ee622847
commit 390fedc848

View File

@ -20,6 +20,9 @@ Register :: struct {
OpName :: enum {
TBD,
MOV,
PUSH,
POP,
XCHG,
ADD,
SUB,
CMP,
@ -69,6 +72,13 @@ registers := [8]Register {
{fullname = "di", bytename = "bh", code = 0b111},
}
segment_registers := [4]Register {
{fullname = "es", code = 0b000},
{fullname = "cs", code = 0b001},
{fullname = "ss", code = 0b010},
{fullname = "ds", code = 0b011},
}
RegInfo :: struct {
in_first_byte: bool,
shift_offset: u8,
@ -82,11 +92,61 @@ OpCodeId :: enum {
LastBit :: struct{}
FourthBit :: struct{}
Force :: struct{}
WordSize :: union {
None,
LastBit,
FourthBit,
Force,
}
None :: struct {}
Disp8 :: i8
Disp16 :: i16
Displacement :: union {
None,
Disp8,
Disp16
}
Value8 :: i8
Value16 :: i16
Data :: union {
None,
Value8,
Value16
}
ModMemory :: struct {}
Mod8BitDisp :: i8
Mod16BitDisp :: i16
ModRegister :: struct {}
ModMode :: union {
ModMemory,
Mod8BitDisp,
Mod16BitDisp,
ModRegister,
}
RegisterId :: distinct u8
Immediate8 :: distinct i8
Immediate16 :: distinct i16
MemoryAddr :: struct {
addr_id: u8,
displacement: Displacement
}
Accumulator :: distinct i16
SegmentRegister :: distinct i8
OperandType :: union {
RegisterId,
Immediate8,
Immediate16,
MemoryAddr,
Accumulator,
SegmentRegister,
}
InstructionInfo :: struct {
@ -182,52 +242,6 @@ instructions := [?]InstructionInfo {
{ opname = .JCXZ, desc = "Jump on not zero", mask = 0b11111111, encoding = 0b11100011, is_jump = true},
}
None :: struct {}
Disp8 :: i8
Disp16 :: i16
Displacement :: union {
None,
Disp8,
Disp16
}
Value8 :: i8
Value16 :: i16
Data :: union {
None,
Value8,
Value16
}
ModMemory :: struct {}
Mod8BitDisp :: i8
Mod16BitDisp :: i16
ModRegister :: struct {}
ModMode :: union {
ModMemory,
Mod8BitDisp,
Mod16BitDisp,
ModRegister,
}
RegisterId :: distinct u8
Immediate8 :: distinct i8
Immediate16 :: distinct i16
MemoryAddr :: struct {
addr_id: u8,
displacement: Displacement
}
Accumulator :: distinct i16
OperandType :: union {
RegisterId,
Immediate8,
Immediate16,
MemoryAddr,
Accumulator,
}
inst_map := make(map[u8]InstructionInfo)
RIGHT_ALIGN_AMOUNT := 35
@ -352,7 +366,7 @@ main :: proc() {
}
defer os.close(f)
data := make([]u8, 512)
data := make([]u8, 1024)
bytes_read, err2 := os.read(f, data)
if err2 != nil {
// ...