c-programming

Simple C programs
git clone git://git.laack.co/c-programming.git
Log | Files | Refs

commit 45cb49fa973d3b12a6a00be792f918b0caa61fd7
parent 4580d3b4d32a41cf9d73bfb8800a7ac5f5bdcd74
Author: Andrew Laack <andrew@laack.co>
Date:   Fri,  9 Oct 2026 23:06:18 -0500

Contd.

Co-authored-by: Vim

Diffstat:
Mperf-aware-programming/8086-decoder/Makefile | 9---------
Mperf-aware-programming/8086-decoder/decode.c | 5+++--
Dperf-aware-programming/8086-decoder/dest/ex4.asm | 95-------------------------------------------------------------------------------
Dperf-aware-programming/8086-decoder/source/ex4 | 0
Dperf-aware-programming/8086-decoder/source/ex4.asm | 92-------------------------------------------------------------------------------
5 files changed, 3 insertions(+), 198 deletions(-)

diff --git a/perf-aware-programming/8086-decoder/Makefile b/perf-aware-programming/8086-decoder/Makefile @@ -8,17 +8,8 @@ run: build ./decode source/ex1 > dest/ex1.asm ./decode source/ex2 > dest/ex2.asm ./decode source/ex3 > dest/ex3.asm - ./decode source/ex4 > dest/ex4.asm - ./decode source/ex4.0 > dest/ex4.0.asm nasm dest/ex1.asm -o dest/ex1 nasm dest/ex2.asm -o dest/ex2 - nasm dest/ex4.asm -o dest/ex4 - nasm dest/ex4.0.asm -o dest/ex4.0 diff dest/ex1 source/ex1 diff dest/ex2 source/ex2 diff dest/ex3 source/ex3 - diff dest/ex4 source/ex4 - # diff dest/ex4.0 source/ex4.0 - # these will differ because of relative - # bytes instead of labels, but I verif - # ied this is correct. diff --git a/perf-aware-programming/8086-decoder/decode.c b/perf-aware-programming/8086-decoder/decode.c @@ -5,6 +5,7 @@ typedef struct { unsigned char opcode; + unsigned char threeDisambiguationBits; unsigned char opcodeUnset; unsigned char d; unsigned char w; @@ -135,7 +136,7 @@ void handleEAC(Instruction inst) { } void printInstructionMnemonic(Instruction inst) { - if(inst.opcode == 34 || inst.opcode == 0b1011) { + if(inst.opcode == 34 || inst.opcode == 11) { printf("mov "); } else { printf("add "); @@ -221,7 +222,7 @@ unsigned char printInstruction(Instruction inst) { } Instruction defaultInstruction() { - Instruction inst = (Instruction){ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0}; + Instruction inst = (Instruction){ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0}; return inst; } diff --git a/perf-aware-programming/8086-decoder/dest/ex4.asm b/perf-aware-programming/8086-decoder/dest/ex4.asm @@ -1,95 +0,0 @@ -add bx, [bx + si] -add bx, [bp] -Sign: 1 -add ax,-31998 -49 -Sign: 1 -add ax,776 -23 -add cx, [bx + 2] -add bh, [bp + si + 4] -add di, [bp + di + 6] -add [bx + si], bx -add [bp], bx -add [bp], bx -add [bx + 2], cx -add [bp + si + 4], bh -add [bp + di + 6], di -Sign: 0 -add al,34 -Sign: 1 -add ax,1000 -7 -17 -add al, [bx + si] -add ax,bx -add al,ah -1 -add ax, [si] -loop 4 -2 -6 -23 -Sign: 1 -add bp,-31998 -59 -Sign: 1 -add bp,11016 -23 -10 -add ch, [bp + si] -jp 4 -10 -1 -6 -23 -10 -add [bx + di], ch -19 -10 -1 -jnp 6 -Sign: 0 -add ch,34 -Sign: 1 -add bp,11037 -17 -10 -10 -10 -mov bp,11267 -loop 44 -2 -6 -23 -Sign: 1 -add di,-31998 -63 -Sign: 1 -add di,15112 -23 -14 -add bh, [bp + si] -jp 4 -14 -1 -6 -23 -14 -add [bx + di], bh -19 -14 -1 -jnp 6 -Sign: 0 -add bh,34 -Sign: 1 -add di,4834 -7 -17 -14 -14 -14 -15 -add di, [si] -loop 60 diff --git a/perf-aware-programming/8086-decoder/source/ex4 b/perf-aware-programming/8086-decoder/source/ex4 Binary files differ. diff --git a/perf-aware-programming/8086-decoder/source/ex4.asm b/perf-aware-programming/8086-decoder/source/ex4.asm @@ -1,92 +0,0 @@ -; ======================================================================== -; -; (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 41 -; ======================================================================== - -bits 16 - -add bx, [bx+si] -add bx, [bp] -add si, 2 -add bp, 2 -add cx, 8 -add bx, [bp + 0] -add cx, [bx + 2] -add bh, [bp + si + 4] -add di, [bp + di + 6] -add [bx+si], bx -add [bp], bx -add [bp + 0], bx -add [bx + 2], cx -add [bp + si + 4], bh -add [bp + di + 6], di -add byte [bx], 34 -add word [bp + si + 1000], 29 -add ax, [bp] -add al, [bx + si] -add ax, bx -add al, ah -add ax, 1000 -add al, -30 -add al, 9 - -sub bx, [bx+si] -sub bx, [bp] -sub si, 2 -sub bp, 2 -sub cx, 8 -sub bx, [bp + 0] -sub cx, [bx + 2] -sub bh, [bp + si + 4] -sub di, [bp + di + 6] -sub [bx+si], bx -sub [bp], bx -sub [bp + 0], bx -sub [bx + 2], cx -sub [bp + si + 4], bh -sub [bp + di + 6], di -sub byte [bx], 34 -sub word [bx + di], 29 -sub ax, [bp] -sub al, [bx + si] -sub ax, bx -sub al, ah -sub ax, 1000 -sub al, -30 -sub al, 9 - -cmp bx, [bx+si] -cmp bx, [bp] -cmp si, 2 -cmp bp, 2 -cmp cx, 8 -cmp bx, [bp + 0] -cmp cx, [bx + 2] -cmp bh, [bp + si + 4] -cmp di, [bp + di + 6] -cmp [bx+si], bx -cmp [bp], bx -cmp [bp + 0], bx -cmp [bx + 2], cx -cmp [bp + si + 4], bh -cmp [bp + di + 6], di -cmp byte [bx], 34 -cmp word [4834], 29 -cmp ax, [bp] -cmp al, [bx + si] -cmp ax, bx -cmp al, ah -cmp ax, 1000 -cmp al, -30 -cmp al, 9