Skip to content

Latest commit

History

78 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

rust-neander

Do you want the easiest way to learning virtual machine and assembly? You've found it!

rust-neander is a virtual machine that runs assembly Neander and Neander+!

They are very didactic hypothetical machines. It is useful if you want to learn more about how a CPU works and how to write a simple assembly code, because Neander and Neander+ were developed in order to be simple for beginners. You will learn these languages and hypothetical machines in a few minutes!

Neander hypothetic machine

  • memory size: 256
  • 8-bit to data width and addresses
  • datas are represented using complement two (if the bit 7 is turn on, the number is negative)
  • one accumalator with 8-bit (AC)
  • one program counter with 8-bit (PC)
  • one status register with 2 condition codes: negative (N) and zero (Z)

Neander+ hypothetic machine

This machine is the same of the above plus:

  • 256 registers to input data (accessible with the IN operator)

Assembly

Both assembly have few operators. Neander+ is compatible with Neander and it has a little more operators.

Neander

Hex codeInstructionDescription
00 ... 1FNOPNo operation
10 ... 1FSTA addressStore the value from AC at the address
20 ... 2FLDA addressLoad at AC the value from the address
30 ... 3FADD addressAdd the AC plus the value from the address
40 ... 4FOR addressUse the OR binary operator with AC and the value from the address
50 ... 5FAND addressUse the AND binary operator with AC and the value from the address
60 ... 6FNOTUse the NOT binary operator with AC
80 ... 8FJMP valueLoad at PC the value
90 ... 9FJN valueIf AC is a negative value, load at PC the value
A0 ... AFJZ valueIf AC is zero, load at PC the value
F0 ... FFHLTFinish the execution

If it tries to execute an nonexistent operator, such as 7A, it will raise an error.

Example to sum 2 and 3:

AddressHex code
0020
0105
0230
0306
04FF
0502
0603

Neander+

Neander+ has five more operators than Neander: SUB, JNZ, IN, OUT, LDI. The remaining operators are the same as the ones Neander has.

Neander+ was inspirated in Neander-X

Hex codeInstructionDescription
70 ... 7FSUB addressSub the AC with the value from the address
B0 ... BFJNZ valueIf AC is not zero, load at PC the value
C0 ... CFIN indexLoad at AC the value the input at the index
D0 ... DFOUTCopy the AC at the out
E0 ... EFLDI valueStore at AC the value

Example to duplicate the value at first position of the input and output the result:

AddressHex code
00C0
0100
0210
0307
0430
0507
06FF
0700

How to execute

To execute your code (for example, that you wrote at ndp/example.ndp file), you can execute it using:

> cargo run ndp/example.ndp

And, to set the inputs used in IN instruction:

> cargo run ndp/example.ndp -i="02 0A"

About

👨‍🏫 Educational purpose virtual machine to assembly Neander and Neander+

Topics

Resources

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages