commit d5389e788c74d1f674f584c264e2216e25e9bc13
parent ea44d7ecfa04c0463d8fca5524632dff2d110169
Author: Andrew Laack <andrew@laack.co>
Date: Fri, 9 Oct 2026 00:05:22 -0500
Continuing
Diffstat:
2 files changed, 49 insertions(+), 39 deletions(-)
diff --git a/perf-aware-programming/8086-decoder/decode.c b/perf-aware-programming/8086-decoder/decode.c
@@ -7,6 +7,7 @@ typedef struct {
unsigned char opcodeUnset;
unsigned char d;
unsigned char w;
+ unsigned char s;
unsigned char mod;
unsigned char reg;
unsigned char rm;
@@ -191,7 +192,7 @@ unsigned char printInstruction(Instruction inst) {
}
// mask then check matches 1011
- } else if(inst.opcode == 0b1011){
+ } else if(inst.opcode == 0b1011 || inst.opcode == 32){
if(inst.dlUnset) {
return 1;
}
@@ -219,7 +220,7 @@ unsigned char printInstruction(Instruction inst) {
}
Instruction defaultInstruction() {
- Instruction inst = (Instruction){ 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0};
+ Instruction inst = (Instruction){ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0};
return inst;
}
@@ -276,7 +277,12 @@ int main(int argc, char** argv) {
inst.immediateToRegister = 1;
} else {
inst.opcode = (buffer[i] & 0b11111100) >> 2;
- inst.d = (buffer[i] & 0b00000010) >> 1;
+ if(inst.opcode == 32) {
+ inst.s = (buffer[i] & 0b00000010) >> 1;
+ printf("Sign: %u\n", inst.s);
+ } else {
+ inst.d = (buffer[i] & 0b00000010) >> 1;
+ }
inst.w = buffer[i] & 0b00000001;
}
inst.opcodeUnset = 0;
diff --git a/perf-aware-programming/8086-decoder/dest/ex4.asm b/perf-aware-programming/8086-decoder/dest/ex4.asm
@@ -1,9 +1,10 @@
add bx, [bx + si]
add bx, [bp]
-32
-add al, [bp + di + 709]
-32
-2
+Sign: 1
+add ax,-31998
+49
+Sign: 1
+add ax,776
23
add cx, [bx + 2]
add bh, [bp + si + 4]
@@ -14,11 +15,12 @@ add [bp], bx
add [bx + 2], cx
add [bp + si + 4], bh
add [bp + di + 6], di
-32
-8
-32
-add bx, [di]
-add ax, [bp]
+Sign: 0
+add al,34
+Sign: 1
+add ax,1000
+7
+17
add al, [bx + si]
add ax,bx
add al,ah
@@ -28,10 +30,11 @@ add ax, [si]
2
6
23
-32
-add al, [bp + di + 749]
-32
-2
+Sign: 1
+add bp,-31998
+59
+Sign: 1
+add bp,11016
23
10
add ch, [bp + si]
@@ -46,23 +49,24 @@ add [bx + di], ch
10
1
30
-32
-8
+Sign: 0
+add ch,34
+Sign: 1
+add bp,11037
+17
10
10
-add [bp + si], ch
-add [bx + di], ch
-54
+10
+mov bp,11267
56
-58
-mov ah,44
2
6
23
-32
-add al, [bp + di + 765]
-32
-2
+Sign: 1
+add di,-31998
+63
+Sign: 1
+add di,15112
23
14
add bh, [bp + si]
@@ -77,20 +81,20 @@ add [bx + di], bh
14
1
30
-32
-8
-15
-4
+Sign: 0
+add bh,34
+Sign: 1
+add di,4834
+7
+17
+14
+14
14
-add [bp + si], bh
-add [bx + di], bh
-54
-56
-58
-15
15
-29
-29
+add di, [si]
+56
+2
+add dh, [di + -4]
29
29
29