Giter VIP home page Giter VIP logo

computer-simulation's Issues

Sub doesn't seem to resolve correctly for results < zero

I have some other suggestions I was thinking of looking at too:

Add decimal output

class _OUTInstruction(_Instruction):
    def process(self, computer):
        print('[OUT] %s - %03d' % (computer._a, int(computer._a, 2))) # include decimal in output
        computer._pc += 1

    def get_basename(self) -> str:
        return 'OUT'

Looks like negatives are not handled correctly. But maybe I am still having to learn more about binary.
This program should load 10 into A, subtract 20 from A and output -10 (11110110 in twos compliment)

➜  Computer-Simulation git:(temp) ✗ cat negative.prg
LDA 15
SUB 14
OUT 0
HLT 0

14: 20
15: 10

but when I compile and run this, I get:

➜  Computer-Simulation git:(temp) ✗ ./cpu.py negative.prg.bin
Loglevel: INFO
[OUT] 11111111 - 255

It works perfectly in cases where the result of the SUB call is > 0.

I will see if there is anything I can do to sort that out. It will mean learning how you structured your code a bit more. But it might be fun...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.