Warning: Update in progress. Before adding new content, I'm going through and updating the content that already existed that I haven't touched in years. Also fixing up a lot of CSS. I wrote bad code a very long time ago and it's taking a while to update it.
This page has not been looked at yet My apologies for any issues this may cause.

5.2 : Programming the CARDIAC


So now that we know the layout of the CARDIAC, let's do some programming. Many verbose coding languages use words like println, or print, or Console.Write to denote something to be outputted to the screen. The CARDIAC does not use any words. It uses numbers. A "Command" consists of two parts, the opcode, and the operand. The opcode is a single number that denotes what happens. The operand is a two digit number that denotes the memory position the opcode is referring to. This forms a 3 digit number. A very important thing to recognize about this 3 digit number, is that it is just a number. Yes, it can perform commands with it. We can also use this number in math. I'll cover this more later. Let's focus on commands right now.

Opcode Operand
0 0 0

So this is a base-10 number. That means each digit can hold numbers 0-9. This means there are 10 different commands to use and 100 different memory points to reference. Like we said above in the Memory section the CARDIAC has 100 memory points. Above we had to formula 2n-1. This tells us how many memory points we have and through which numbers they're labelled. Since we're using base-10 we sub 10 in for 2. Since there are 2 digits, n=2. Then calculate 102-1 = 99. This means we have memory points 00-99. This makes sense since we have two base-10 digits which have numbers ranging 0-9. Below are the opcodes for the CARDIAC and which operation each corresponds to. You don't have to memorize it, however, after doing many programs you might.

Opcode Abbreviation Operation
0 INP Read a card into memory
1 CLA Clear accumulator and add from memory
2 ADD Add from memory into accumulator
3 TAC Test accumulator. Jump to memory if negative
4 SFT Shift accumulator
5 OUT Write memory to output
6 STO Store accumulator into memory
7 SUB Subtract memory from accumulator
8 JMP Jump to memory position
9 HRS Halt and Reset: Ends the Program

Notice how when I described each operation, I mentioned how the memory relates to the operation. The first digit corresponds to the opcode. The second two being to the memory point it references. Let's say we have the number 103 and in memory point 03 we have the number 002. The opcode 1 means we have to clear the accumulator. Then we add whatever is in memory point 03. This means 002 is now what is in the accumulator. If we use the command 800, it means we jump (8) to memory point 00.

If you notice, there are two commands that do not relate to the memory, SFT (4) and HRS (9). Since HRS halts and resets the program, you do not need to reference a memory point. SFT on the other hand is a little more difficult. The first digit in SFT is 4. Right now we have 4--. The second digit shifts the digits in the accumulator over to the left n amount of places. If 1234 was stored in the accumulator, and we called 42-, it would shift the places to now 3400. We have now lost the values 1 and 2. We cannot retrieve them. They are lost. The third digit in the SFT operation shifts the accumulator to the right n amount of digits. So if we have 422, 1234 first becomes 3400. The accumulator shifts the other way and becomes 0034. Like I said before, when the accumulator shifts, you lose the digits.


Back To Top