4

I'm looking for some sample code that "emulates" the most frequently used math instructions(addition,subtraction,multiplication,division) and will cover all steps that a hardware based cpu processor follows.

The first thing i did was to use google and got this : https://bochs.svn.sourceforge.net/svnroot/bochs/trunk/bochs/cpu/

But its not what i want.This is an instruction wrapper/emulator while i want to see how the cpu does everything down to bit level...

..

user1010005
  • 2,617
  • 5
  • 22
  • 20

4 Answers4

2

TTL is a great way to get introduced to digital logic. If you search Google for something like "TTL arithmetic", you'll probably get lots of links to tutorials about how to create things like adders and multipliers.

(Of course knowing what to search for is half the problem.)

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
1

You should Google for two's complement arithmetic.

This Computer Arithmetic Algorithms Simulator may interest you.

Borodin
  • 126,100
  • 9
  • 70
  • 144
1

If you really want 'code that "emulates",' (in its literal terms) you'll need a parser for Boolean Algebra grammar:

S ::= E;
E ::= (E)
E ::= T AND T
E ::= T OR T
E ::= T NOR T
T ::= NOT T
T ::= IDENTIFIER # Set of named bits
...
Include grammar for STATEMENTs.

Simply, write a parser for the above grammar so that you can start writing code in Boolean Algebra.

# Half Adder
SUM = A NOR B;
CARRY = A AND B;

Edit: I realize that this SO question already defines a solution. Boolean expression (grammar) parser in c++


From here, you can build an Arithmetic Logic Unit (ALU) in the von Neumann Architecture that should be able to handle of the aforementioned arithmetic: http://en.wikibooks.org/wiki/Microprocessor_Design/ALU

Community
  • 1
  • 1
Gio Borje
  • 20,314
  • 7
  • 36
  • 50
1

The Wikipedia article on the arithmetic logic unit (ALU) has a number of links which might be useful to you. Among them articles about addition, multiplication and division.

MvG
  • 57,380
  • 22
  • 148
  • 276