commit 5fba1092c3764d1f25e95a4543e3a39f32778390
parent aa7ac9de9ffc7eb199debc843d3c9c0f119740f3
Author: Andrew Laack <andrew@laack.co>
Date: Mon, 12 Oct 2026 19:09:21 -0500
Working on simulation
Diffstat:
9 files changed, 127 insertions(+), 1 deletion(-)
diff --git a/perf-aware-programming/8086-ref/Makefile b/perf-aware-programming/8086-ref/Makefile
@@ -1,2 +1,6 @@
build:
- g++ sim86.cpp
+ g++ sim.cpp -o simulate
+
+run: build
+ ./simulate source/listing_0043_immediate_movs
+ ./simulate source/listing_0044_register_movs
diff --git a/perf-aware-programming/8086-ref/sim.cpp b/perf-aware-programming/8086-ref/sim.cpp
@@ -0,0 +1,52 @@
+#include <stdint.h>
+
+#include "sim86.h"
+
+#include "sim86_memory.h"
+#include "sim86_text.h"
+#include "sim86_decode.h"
+
+#include "sim86_memory.cpp"
+#include "sim86_text.cpp"
+#include "sim86_decode.cpp"
+
+typedef struct {
+ u32 index;
+ u8 size;
+} Register;
+
+Register AX {0,2};
+Register AH {0,1};
+Register AL {1,1};
+
+Register BX {2,2};
+Register BH {2,1};
+Register BL {3,1};
+
+Register CX {4,2};
+Register CH {4,1};
+Register CL {5,1};
+
+Register DX {6,2};
+Register DH {6,1};
+Register DL {7,1};
+
+int main(int argc, char** argv) {
+ // first 8 bytes are registers.
+ unsigned char stateBuffer[1024*1024];
+ u8 done = 0;
+ FILE* fp = fopen(argv[1], "rb");
+
+ if(fp == NULL) {
+ return -1;
+ }
+
+ unsigned char buffer[65536];
+
+ u32 n = fread(buffer, 1, sizeof(buffer), fp);
+
+ for(u32 i = 0; i < n; ++i) {
+ printf("%hhd", buffer[i]);
+ }
+ fclose(fp);
+}
diff --git a/perf-aware-programming/8086-ref/simulate b/perf-aware-programming/8086-ref/simulate
Binary files differ.
diff --git a/perf-aware-programming/8086-ref/source/listing_0043_immediate_movs b/perf-aware-programming/8086-ref/source/listing_0043_immediate_movs
Binary files differ.
diff --git a/perf-aware-programming/8086-ref/source/listing_0043_immediate_movs.asm b/perf-aware-programming/8086-ref/source/listing_0043_immediate_movs.asm
@@ -0,0 +1,27 @@
+; ========================================================================
+;
+; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
+;
+; This software is provided 'as-is', without any express or implied
+; warranty. In no event will the authors be held liable for any damages
+; arising from the use of this software.
+;
+; Please see https://computerenhance.com for further information
+;
+; ========================================================================
+
+; ========================================================================
+; LISTING 43
+; ========================================================================
+
+bits 16
+
+mov ax, 1
+mov bx, 2
+mov cx, 3
+mov dx, 4
+
+mov sp, 5
+mov bp, 6
+mov si, 7
+mov di, 8
diff --git a/perf-aware-programming/8086-ref/source/listing_0044_register_movs b/perf-aware-programming/8086-ref/source/listing_0044_register_movs
Binary files differ.
diff --git a/perf-aware-programming/8086-ref/source/listing_0044_register_movs.asm b/perf-aware-programming/8086-ref/source/listing_0044_register_movs.asm
@@ -0,0 +1,32 @@
+; ========================================================================
+;
+; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
+;
+; This software is provided 'as-is', without any express or implied
+; warranty. In no event will the authors be held liable for any damages
+; arising from the use of this software.
+;
+; Please see https://computerenhance.com for further information
+;
+; ========================================================================
+
+; ========================================================================
+; LISTING 44
+; ========================================================================
+
+bits 16
+
+mov ax, 1
+mov bx, 2
+mov cx, 3
+mov dx, 4
+
+mov sp, ax
+mov bp, bx
+mov si, cx
+mov di, dx
+
+mov dx, sp
+mov cx, bp
+mov bx, si
+mov ax, di
diff --git a/perf-aware-programming/shared-lib/app.c b/perf-aware-programming/shared-lib/app.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int dbl(int a);
+
+int main() {
+ int num = 10;
+ printf("%d", dbl(num));
+}
diff --git a/perf-aware-programming/shared-lib/lib.c b/perf-aware-programming/shared-lib/lib.c
@@ -0,0 +1,3 @@
+int dbl(int a) {
+ return a * 2;
+}