MCA (Old)

From Esolang
Jump to navigation Jump to search

MCA is a programming language designed by user:Almostahexagon (need to replace later with the actual username) for the purpose of creating an assembly language for a mechanical computer. MCA stands for Mechanical Computer Assembly.

NOTE: This is the old version! Please check out the new one (when it's done). Version 1.1 only shows that has changed, so this page is helpful for background information.

                          ┌─────────────────────────┐
                          │                         │
                          │                         │
          data in         │       Program RAM       │        ┌─Flags───────┐
 ┌────────────────────────┤         Progrom         │        │+│is Positive│
 │                        │                         ◄──────┐ │-│is Negative│
 │                        │                         │      │ │0│is Zero    │
 │                        └───────────────────┬─────┘      │ │c│Carry      │
 │                                            │            │ └─┴───────────┘
 │             MeComp                         │          Flags
 │       Mechanical Computer                Opcode         │
 │                                            │            │
 │                                            │            │
 │                  ┌─────────────┐        ┌──▼────────────┴──┐
 │  ┌───┐           │             ├──M1────►                  │
 └──►   │           │             │        │    Arithmetic    │
    │   │           │     RAM     ├──M0────►       Unit       │
┌───►   ├─data in───►             │        │                  ├─┐
│   │   │           │             ├──┐     └──────────────────┘ │
│ ┌─►   │           └──────▲───▲──┘  │                          │
│ │ └───┘                  │   │     │   ┌─────────┐            │
│ │                        │   │     │   │ Display │            │
│ └───────────label────────┼───┼─────┘   └─▲───────┘            │
│                          │   │           │                    │
└──────────────────────────┼───┼───────────┴──AU Result─────────┘
                           │   │
                           ▼   ▼
                            I/O

Mechanical computer information

Memory

MCA uses a RAM as it's memory. This can be emulated, and doesn't have to be using actual RAM. Each "cell" is 8 bits, ranging from 00-FF or 0-255. There are 256 of these "cells".

In this page, memory "cells" will be referred as M#, where the # is replaced with an address in hex.

M0 and M1 will always be used as the 2 AU inputs.

AU

The AU (arithmetic unit) is where all the calculations happen. It's not ALU because there's no logic. On every cycle, it will take M0 and M1 and do an operation, if specified. The result will output a certain flag. So, if you wanted to add 1 and 2, for example, you would load 1 into M0 and 2 into M1, then give the add instruction. The AU will then output the is positive flag because the result was positive. If no AU operation was specified, then nothing happens.

Reserved memory cells

These cannot be used in the program.

M2 is always -1, M3 is always 0, and M4 is always 1. M254 and M255 are the two I/O ports.

If you try to write to M2-M4, they will be ignored.

Instruction writing

Writing instructions to the computer isn't fully clear yet. In this page, instructions (or lines) will be in the format of I#, where # is a line in hex.

AU flags

The AU will output four different flags, depending on the last AU result.

  • is Zero
  • is Negative
  • is Positive
  • carry

(insert whatever the carry flag actually does) The carry flag is enabled/raised/met (edit) when the last AU operation results in a carry out at the end.

An example would be if you're adding 100 and 101. You would line them up like this:

  1 0 0
+ 1 0 1
-------
1 0 0 1
^

When you add the numbers, you get a carry at the end (meaning it required an extra bit).

Instructions

Conditional branching

Opcode Name Full name Parameter A Parameter B Function
000 JMP Jump Condition Destination Jumps to I[Destination] if the [Condition] AU flag is met/raised (pls edit). See AU flags for more info about flags.

Memory management

Opcode Name Full name Parameter A Parameter B Function
001 LOD Load Value Destination address Loads [Value] into [Destination address] of memory.
010 CPY Copy Address Destination Copies [Address] to [Destination].
011 UIP User input 1 byte from user Destination Takes an 8-bit input from the user and loads it into [Destination].

AU operations

Opcode Name Full name Parameter A Parameter B Function
100 ADD Load Destination AU takes M0 and M1 and adds them together. Result goes in [Destination]. Does
101 SUB Subtract Destination Does the same thing as ADD, but subtracts instead. Does
110 ASB A-shift-B Destination Takes M0 and shifts it by M1 bits. Does
111 2SC 2's Complement Destination Takes M0 and outputs the Two's Complement result into [Destination]. Does

Jump command information

The jump command looks like this:

JMP ? I#

Where ? is one of the below, and I# is the line to jump to. Jumping to IFF will halt the CPU.

U Unconditionally (no matter what)
+ is Positive
- is Negative
0 is Zero
c carry

Output

Notice how there's no output command. If you look at the diagram, there is a display. The display will just output the last AU result, so that means number-only output.

Examples

Add 2 numbers (A+B problem)

User input version:

0 | UIP M0
1 | UIP M1
2 | ADD M0

Truth-machine

 0 | UIP M0
 1 | JMP + IB
 2 | JMP 0 I5
 3 |
 4 | // 0
 5 | LOD 0 M0
 6 | LOD 0 M1
 7 | ADD M0
 8 | JMP U IFF
 9 |
 A | // 1
 B | LOD 0 M0
 C | LOD 1 M0
 D | ADD M0
 E | LOD 0 M1
 F | ADD M0
10 | JMP IF

Note: I don't know if this works properly