diff --git a/asm_files/list-0043.txt b/asm_files/list-0043.txt new file mode 100644 index 0000000..9b5a0e8 --- /dev/null +++ b/asm_files/list-0043.txt @@ -0,0 +1,19 @@ +--- test\listing_0043_immediate_movs execution --- +mov ax, 1 ; ax:0x0->0x1 +mov bx, 2 ; bx:0x0->0x2 +mov cx, 3 ; cx:0x0->0x3 +mov dx, 4 ; dx:0x0->0x4 +mov sp, 5 ; sp:0x0->0x5 +mov bp, 6 ; bp:0x0->0x6 +mov si, 7 ; si:0x0->0x7 +mov di, 8 ; di:0x0->0x8 + +Final registers: + ax: 0x0001 (1) + bx: 0x0002 (2) + cx: 0x0003 (3) + dx: 0x0004 (4) + sp: 0x0005 (5) + bp: 0x0006 (6) + si: 0x0007 (7) + di: 0x0008 (8) diff --git a/execution.odin b/execution.odin index 70b38a8..b08c44a 100644 --- a/execution.odin +++ b/execution.odin @@ -10,13 +10,13 @@ execute_instruction :: proc(inst: Instruction) { case .MOV: if reg_id,ok := inst.dst.(RegisterId); ok { #partial switch val in inst.src { - case Immediate8: + case Immediate8: registers[reg_id].value.low = (u8)(val) - case ImmediateU8: + case ImmediateU8: registers[reg_id].value.low = (u8)(val) - case Immediate16: - registers[reg_id].value.low = (u8)(val) - case RegisterId: + case Immediate16: + registers[reg_id].value.full = (u16)(val) + case RegisterId: registers[reg_id].value.full = registers[val].value.full } } diff --git a/sim8086.odin b/sim8086.odin index a8896f9..e099bc9 100644 --- a/sim8086.odin +++ b/sim8086.odin @@ -94,7 +94,7 @@ main :: proc() { 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) + hex := fmt.aprintf("0x%04x ", 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() diff --git a/test_registers.sh b/test_registers.sh new file mode 100755 index 0000000..9b1d487 --- /dev/null +++ b/test_registers.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +make asm_files > /dev/null + +if [ ! "$(command -v ./sim8086)" ]; then + echo -e "\nError: 'sim8086' executable not found" + exit 1 +fi + +odin build . -out:sim8086 + +for asm_txt in asm_files/*.txt; +do + asm_listing=$(basename $asm_txt .txt) + ./sim8086 asm_files/${asm_listing}.bin | awk '{print $1 ":" $5}' | sort > temp1 + cat $asm_txt | awk '/Final registers/,0' | tail -n +2 | awk '{print $1 $2}' | sort > temp2 + diff -U0 --color temp1 temp2 + rm temp1 temp2 +done