c-programming

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

commit d1149a2cdb83c6df97043cdc5e1ea46cf137c98f
parent 72c1f1c700d60fcaa3aa388adaad3450d0c5b4fb
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 14 Oct 2026 20:29:47 -0500

Support for basic mov-based store / load

Diffstat:
Mperf-aware-programming/8086-simulator/Makefile | 1+
Mperf-aware-programming/8086-simulator/sim.cpp | 31++++++++++++++++++++++++++-----
2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/perf-aware-programming/8086-simulator/Makefile b/perf-aware-programming/8086-simulator/Makefile @@ -8,3 +8,4 @@ run: build ./sim.out source/0048.asm ./sim.out source/0049.asm ./sim.out source/0051.asm + ./sim.out source/0051a.asm diff --git a/perf-aware-programming/8086-simulator/sim.cpp b/perf-aware-programming/8086-simulator/sim.cpp @@ -222,7 +222,15 @@ std::string handleInstruction(std::string source, std::string dest, std::vector< } catch (...) { auto num = getReg(dest); if(num == -1) { - std::cout << "UNFOUND REG" << std::endl; + uint16_t destAddr = std::stoi(dest.substr(1,dest.size()-2)); + uint16_t val1 = (memory[destAddr]); + uint16_t val2 = (memory[destAddr+1]); + val1 = (val1 << 8); + uint16_t val = val1 + val2; + auto src = getReg(source); + auto before = registers[src/2].second; + printf("\t; start in: 0x%.2X \t\tval: 0x%.2X->0x%.2X", in, before , val); + registers[src/2].second = val; return ""; } auto destVal = valueAt(registers,num); @@ -260,17 +268,25 @@ std::string handleInstruction(std::string source, std::string dest, std::vector< // not moving to register (e.g. store) std::string sourceVS = source.substr(1); sourceVS = sourceVS.substr(0,sourceVS.size() - 1); - uint16_t sourceAddr = std::stoi(sourceVS); + + uint16_t sourceAddr; + + if(getReg(sourceVS.substr(0,2)) != -1) { + sourceAddr = registers[getReg(sourceVS.substr(0,2)) / 2].second; + sourceAddr += std::stoi(sourceVS.substr(5)); + } else { + sourceAddr = std::stoi(sourceVS); + } uint16_t destV = std::stoi(dest); // little endian so re-order bytes - uint16_t lower = (destV << 8); uint16_t upper = (destV >> 8); destV = lower + upper; - printf("\t;\t\t\t\tval: 0x%.2X->0x%.2X", memory[sourceAddr] , destV); - memory[sourceAddr] = destV; + printf("; start in: 0x%.2X \t\t\tval: 0x%.2X->0x%.2X", memory[sourceAddr] , destV); + memory[sourceAddr] = upper; + memory[sourceAddr+1] = (lower >> 8); } return ""; } @@ -332,8 +348,13 @@ int main(int argc, char** argv) { auto source = sourceP.first; auto dest = destP.first; + if(dest[0] == '+') { + dest = dest.substr(dest.find(']') + 3); + } + if(mne != FN) { if(mne != JNZ) { + std::cout << source << ", " << dest; } else { std::cout << source;