Advertisement
Guest User

C4C 8-bit Computer Complete Specification

a guest
Jun 7th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.25 KB | None | 0 0
  1. C4C 1 Computer Datasheet & Specification (C) Cool4Cool 2016 - 2017
  2. PowderToy Simulator @ https://www.powdertoy.co.uk
  3.  
  4. I. Overview
  5. The C4C 1 is a computer designed and built in Powdertoy by me, Cool4Cool. It is based on several different technologies, using
  6. elements of filt/aray/dtec, inst technology, even containing one subframe ray gun.
  7. It includes:
  8. - An 8-bit Semi-Von Neumann architecture (data/addresses are 8 bits wide at maximum)
  9. - A 256 byte ROM and 256 byte RAM
  10. - 16 general purpose registers (AX - PX)
  11. - Hex I/O
  12. - An ALU that shifts, adds, and does logical operations
  13. - Three jump instructions
  14. - A 21 bit bus
  15.  
  16.  
  17.  
  18. II. Table of Contents
  19. - 1. General Architecture
  20. 1.1 Overview
  21. 1.2 The Components of the Computer
  22. 1.2.0 Intro
  23. 1.2.1 The CPU
  24. 1.2.2 The ROM
  25. 1.2.3 The RAM
  26. 1.2.4 The Registers Unit
  27. 1.2.5 The Instruction Pointer
  28. 1.2.6 The Conditionals Unit
  29. 1.2.7 The ALU
  30. 1.2.8 The I/O Unit
  31. 1.3 The Bus
  32. 1.3.0 Intro
  33. 1.3.1 How the Bus Works (Bus Specification)
  34. 1.3.2 Microcode
  35. 1.3.3 Individual Component Microcode Commands
  36. 1.3.3.0 Intro
  37. 1.3.3.1 The CPU
  38. 1.3.3.2 The ROM
  39. 1.3.3.3 The RAM
  40. 1.3.3.4 The Register Unit
  41. 1.3.3.5 The Instruction Pointer
  42. 1.3.3.6 The Conditionals Unit
  43. 1.3.3.7 The ALU Accumulator
  44. 1.3.3.8 The ALU Secondary
  45. 1.3.3.9 The I/O Unit
  46. 1.4 The Operation of the CPU
  47. 1.4.0 Intro
  48. 1.4.1 Instructions vs. Data
  49. 1.4.2 Executing an Instruction
  50. 1.4.3 Operands
  51. 1.4.4 Register Operands
  52.  
  53. - 2. Programming Reference
  54. 2.1 Overview/Intro
  55. 2.2 Basic Programming
  56. - HLT
  57. - MOV
  58. - STORE
  59. - LOADRAM
  60. - LOADROM
  61. - DB
  62. - JMP
  63. - JZ
  64. - JNZ
  65. - OR
  66. - AND
  67. - NOT
  68. - SHL
  69. - SHR
  70. - ADD
  71. - RECV
  72. - SEND
  73. 2.3 Advanced Information
  74. - HLT
  75. - MOV
  76. - STORE
  77. - LOADRAM
  78. - LOADROM
  79. - DB
  80. - JMP
  81. - JZ
  82. - JNZ
  83. - OR
  84. - AND
  85. - NOT
  86. - SHL
  87. - SHR
  88. - ADD
  89. - RECV
  90. - SEND
  91. 2.4 Example Programs
  92. 2.4.1 Fibbonnaci Sequence Program
  93. 2.4.2 Input/Output
  94.  
  95.  
  96.  
  97. 1. General Architecture
  98. 1.1 Overview
  99. This section of the document will describe everything related to the design of the C4C 1 and its architecture.
  100. It will cover a lot of ground, ranging from the facilities/components of the C4C 1 to the instruction design to
  101. the bus.
  102.  
  103. 1.2 The Components
  104. 1.2.0 Intro
  105. A computer is a really difficult and complex thing to describe to the minute details. Where do we start? I would
  106. try describing the components first, to break the "thing" down into tangible components. I define a component as
  107. anything that connects and communicates with the rest of the computer through the bus. Note that I will not get very
  108. technical here about each component's operation on the bus (go to the next section, 1.3). This is a general description.
  109.  
  110. 1.2.1 The CPU
  111. The CPU is the most important and complicated part of a computer to implement. In the C4C 1, the CPU, Instruction Pointer, and
  112. ROM are attached together. The Instruction Pointer outputs an 8 bit number into the ROM, which reads it as an address and uses to
  113. outputs a value into the CPU. If the value is an instruction, the CPU divides the instruction into its elements and
  114. decodes it, caching operands for later. If the value is stored data, the CPU ignores it.
  115.  
  116. Now, we come to an important stage of the CPU's execution. The CPU relies on <<microcode>> in order to control the rest of the
  117. computer over the bus. Microcode is basically hardware commands, each unit on the bus is addressed and has commands
  118. that it can understand. More on this in the next section (1.3). The CPU stores this microcode prewired, and puts it on the bus with
  119. the operands after processing. The other units understand this, and use the commands to do things. Note that every unit has its own
  120. unique commands that only it understands, making microcode and a bus more efficient than a maze of wires that is difficult to
  121. design and navigate.
  122.  
  123. 1.2.2 The ROM
  124. The ROM is vital to the computer's execution. It is a 256 byte FILT memory unit that contains the pre-loaded programs you write.
  125. In the C4C 1, the CPU, Instruction Pointer, and ROM are attached together, as said in 1.2.1 (The CPU). The ROM receives
  126. addresses from the Instruction Pointer, and sends off instructions to the CPU. The ROM is also directly connected to the bus,
  127. which allows programs to access it with the LOADROM instruction. You see, the ROM can also store data, which is distinguished
  128. from instructions in a way that I will describe in section 1.4. This allows you to load data from the ROM directly into the
  129. registers.
  130.  
  131. 1.2.3 The RAM
  132. The RAM is a ROM unit that I created, modified to be writeable. It is 256 bytes of FILT memory that you can read or write
  133. from, and it can be written to and read from with the LOADRAM and STORE instructions, as it is also connected to the bus.
  134. This should be used for more long term storage of constants, as it is significantly slower than the registers.
  135.  
  136. 1.2.4 The Registers Unit
  137. The registers unit is made up of 16 registers (AX - PX). These registers are used for practically everything, from doing
  138. arithmetic/logic, to conditional operations, to input/output. The LOADROM and LOADRAM instructions load data into the
  139. registers, and the STORE instruction saves them into the RAM. The MOV instruction copies the value of one register to another.
  140.  
  141. 1.2.5 The Instruction Pointer
  142. The instruction pointer keeps track of which address the computer is on in the ROM. It feeds into the ROM, which feeds into
  143. the CPU. You cannot read from the instruction pointer, only write to it with the JMP, JZ or JNZ instructions. It is a special
  144. incrementable register adapted to keep track of instructions.
  145.  
  146. 1.2.6 The Conditionals Unit
  147. The conditionals unit handles the conditional jumps, JZ and JNZ. It will check if a register value that is sent to it is zero
  148. or not, before choosing whether to change the instruction pointer's address or not.
  149.  
  150. 1.2.7 The Arithmetic/Logic Unit
  151. This large unit can be described very simply, it controls all of the logical, bitwise, and arithmetic operations - it receives
  152. the values and which operation to do from the bus, and outputs back the result. Inside the ALU, there is an adder, an OR unit,
  153. an AND unit, a NOT unit, and a shifter unit. It can be used through the ADD, NOT, AND, OR, SHL, and SHR instructions. The adder
  154. is interesting - instead of a traditional ripple carry adder, it is a modified binary counter - it accepts input like a normal
  155. register through 8 bits - but if more data is written onto it without clearing it it operates like a binary counter and ends
  156. up adding the two numbers.
  157.  
  158. 1.2.8 The I/O Unit
  159. The I/O unit communicates with external devices. It takes the data on the bus and outputs it to an external
  160. device, or reads from a input device and outputs its data on the bus.
  161.  
  162. 1.3 The Bus
  163. 1.3.0 Intro
  164. Now that all the components have been described, I will describe the bus, which connects all of the various components
  165. together under a common protocol that can be used for communication. The bus is basically a bunch of wires (more specifically, 21)
  166. placed right next to each other, that are used for signaling. It is the lifeline of the computer. Every component connects to it
  167. and communicates over it. Without it, the CPU would sit silent, unable to control the other units.
  168.  
  169. 1.3.1 How the Bus Works
  170. Now that we now what the bus is, I will describe how it works. The bus's 21 wires are divided into two sections that serve
  171. different purposes. There is the 12 bit command (CMND) section of the bus, and the 8 bit data section of the bus (DATA).
  172.  
  173. But there are 21 wires! What does the last one do? The last wire (P) signals all the components to read what is on the bus and
  174. process the information. If the address specified by the command section of the bus is not the address of a unit that processes
  175. it, that unit will ignore the data on the bus and let the unit with the correct address process the bus. Altogether, this is what
  176. the bus looks like in terms of bits:
  177.  
  178. [x][xxxxxxxxxxxx][xxxxxxxx]
  179. [P][ CMND ][ DATA ]
  180.  
  181. The command and data sections of the bus play unique roles. The data section of the bus carries, well, data. This can be anything
  182. from numbers to addresses depending on the purpose, as long as it fits in 8 bits. The command section is split into two parts. The
  183. first part is a 4 bit address that is unique for every unit that is on the bus. The second part is a command the unit will
  184. understand. It can be anything, as long as it fits into 8 bits. So, the data and command sections would look like this:
  185.  
  186. Command Section:
  187. [xxxx][xxxxxxxx]
  188. [ADDR][ CMND ]
  189.  
  190. Data Section:
  191. [xxxxxxxx]
  192. [ DATA ]
  193.  
  194. 1.3.2 Microcode
  195. The job of the CPU is to control the components/units over the bus. We have discussed the protocol for communication over the bus.
  196. Here, I will explain how the CPU takes an instruction given to it from ROM and puts it on the bus - how it controls the components.
  197. After the operands are cached, the CPU needs to assemble a command for the bus. To do this, it selects a predefined sequence of
  198. bits from the correct place in a special memory unit, to put on the bus along with the correctly formatted operands.
  199. These predefined sequences of bits form the microcode, and are what the CPU uses to control the units in the C4C 1.
  200. They in essence form the CPU! The completed sequence is output onto the bus, and the targeted unit returns data back to the CPU for
  201. further processing. Even if there is no data to return, the P line is still signaled in order for the CPU to continue execution.
  202. In a single instruction, there may be multiple steps the units need to take in order to execute it, for example, there are 5 steps
  203. the units need to take to add the contents of two registers together. Therefore, there can be multiple microcode sequences that are
  204. executed sequentially for each instruction, with every signal back to the CPU over the P line from a unit causing the CPU to move
  205. on to the next line of microcode until the instruction is executed.
  206.  
  207. 1.3.3 Individual Component Microcode Commands
  208. 1.3.3.0 Intro
  209. This section is a reference of all the different microcode sequences the CPU puts on the bus to
  210. drive the components. Each component is different, understands different commands and has
  211. a different address on the bus. Here is a list of each unit's commands/data received, and the data it outputs to CPU.
  212.  
  213. 1.3.3.1 CPU
  214. - Address: 0000
  215. - Input from Bus to CPU:
  216. [1][0000][00000000][xxxxxxxx]
  217. [P][ADDR][ CMND ][ DATA ]
  218. When a component processes the CPU's commands from the bus, it sends the data output back
  219. to the CPU for the next step in executing an instruction
  220. - Output from CPU to Bus:
  221. [1][xxxx][xxxxxxxx][xxxxxxxx]
  222. [P][ADDR][ CMND ][ DATA ]
  223. The CPU, to control a component, outputs its address, CMND, and DATA
  224. (usually mixed with operands) onto the bus
  225.  
  226. 1.3.3.2 ROM
  227. - Address: 0001
  228. - Input from Bus to ROM:
  229. [1][0001][xxxxxxxx][00000000]
  230. [P][ADDR][ CMND ][ DATA ]
  231. The command is an address from the bus that corresponds to a byte of data in memory
  232. - Output from ROM to Bus:
  233. [1][0000][00000000][xxxxxxxx]
  234. [P][ADDR][ CMND ][ DATA ]
  235. The byte of data in the ROM is output back to the CPU on the bus
  236.  
  237. 1.3.3.3 RAM
  238. - Address: 0010
  239. - Input from Bus to RAM:
  240. [1][0010][xxxxxxxx][xxxxxxxx][x]
  241. [P][ADDR][ CMND ][ DATA ][W]
  242. The command is an address from the bus that corresponds to a byte of data in memory, W is an optional direct write
  243. line from the CPU to the RAM that, if turned on, puts the RAM into write mode. In that case, the data section of
  244. the bus is written to the address specified by the command section
  245. - Output from RAM to Bus:
  246. [1][0000][00000000][xxxxxxxx]
  247. [P][ADDR][ CMND ][ DATA ]
  248. If W was not turned on, then the data corresponding to the requested address is output back to the CPU on the bus
  249.  
  250. 1.3.3.4 Registers Unit
  251. - Address: 0011
  252. - Input from Bus to Registers Unit:
  253. [1][0011][xxxxxxxx][xxxxxxxx]
  254. [P][ADDR][ CMND ][ DATA ]
  255. CMND consists of [xxxx][xxxx] address of register and instruction,
  256. [ADDR][INST] which can be 0000 (read) or 0001 (write)
  257. If INST is 0001 (write), then DATA is written to the register
  258. - Output from Registers Unit to Bus:
  259. [1][0000][00000000][xxxxxxxx]
  260. [P][ADDR][ CMND ][ DATA ]
  261. The data the register held is output onto the bus if INST is 0000 (read)
  262.  
  263. 1.3.3.5 Instruction Pointer
  264. - Address: 0100
  265. - Input from Bus to Instruction Pointer:
  266. [1][0100][xxxxxxxx][00000000]
  267. [P][ADDR][ CMND ][ DATA ]
  268. CMND is the address to change the instruction pointer to
  269. - Output from Instruction Pointer to Bus:
  270. [1][0000][00000000][00000000]
  271. [P][ADDR][ CMND ][ DATA ]
  272. Signals back to the CPU that the instruction pointer was changed
  273.  
  274. 1.3.3.6 Conditionals Unit
  275. - Address: 0101
  276. - Input from Bus to Conditionals Unit:
  277. [1][0101][xxxxxxxx][xxxxxxxx][x]
  278. [P][ADDR][ CMND ][ DATA ][I]
  279. CMND is the address of an instruction in ROM to which to jump if the condition is met, and DATA is the data to check
  280. for meeting the condition. I is a special direct line from the CPU to the conditionals unit which determines whether
  281. to return positive for zero or not-zero (JNZ vs JZ). 1 is JZ and 0 is JNZ.
  282. - Output from Conditionals Unit to Bus:
  283. [1][xxxx][xxxxxxxx][00000000]
  284. [P][ADDR][ CMND ][ DATA ]
  285. Returns command to instruction pointer (sets ADDR to 0100) IF CONDITION MET, CMND is the address of the instruction to
  286. JMP to. If CONDITION NOT MET, there is no data to send, and ADDR is set to the CPU (0000)
  287.  
  288. 1.3.3.7 ALU Accumulator
  289. - Address: 0110
  290. - Input from Bus to ALU Accumulator:
  291. [1][0110][xxxxxxxx][xxxxxxxx]
  292. [P][ADDR][ CMND ][ DATA ]
  293. CMND consists of [0000][xxxx] INST is the operation to take (OR, AND, NOT, SHL, SHR, ADD)
  294. [INST] numbered from 0000 - 0101 in order
  295. Data is the number to put into the accumulator
  296. ALU Secondary is Operand B, Accumulator is Operand A
  297. - Output from ALU Accumulator to Bus:
  298. [1][0000][00000000][xxxxxxxx]
  299. [P][ADDR][ CMND ][ DATA ]
  300. This is the result of operation - the ALU Secondary would be loaded first, then signal the CPU using the P line on
  301. the bus. Then, ALU Accumulator would be loaded with data and the command, and the ALU would operate
  302. and return the value on the accumulator to the CPU
  303.  
  304. 1.3.3.8 ALU Secondary
  305. - Address: 0111
  306. - Input from Bus to ALU Secondary:
  307. [1][0111][00000000][xxxxxxxx]
  308. [P][ADDR][ CMND ][ DATA ]
  309. DATA is the register value to put into the ALU secondary operand
  310. - Output from ALU Secondary to Bus:
  311. [1][0000][00000000][00000000]
  312. [P][ADDR][ CMND ][ DATA ]
  313. Signals back to the CPU that the operand was loaded in
  314.  
  315. 1.3.3.9 I/O Unit
  316. - Address: 1000
  317. - Input from Bus to I/O Unit:
  318. [1][1000][xxxxxxxx][xxxxxxxx]
  319. [P][ADDR][ CMND ][ DATA ]
  320. CMND consists of [0000][xxxx] which dictates whether to input data to the CPU or write data onto peripheral
  321. [INST] to peripheral (0000 = write data to peripheral, 0001 = input data back to CPU over bus)
  322. DATA is loaded data from the bus - INST 0000 writes it out to the peripheral
  323. - Output from I/O Unit to Bus:
  324. [1][0000][00000000][xxxxxxxx]
  325. [P][ADDR][ CMND ][ DATA ]
  326. If INST is 0000, then unit writes data that came externally onto the bus
  327.  
  328. 1.4 The Operation of the CPU
  329. 1.4.0 Intro
  330. This section is going to discuss the operation of the CPU more in-depth. We will take a look at the difference
  331. between instructions and data, how the CPU interprets instructions, and more.
  332.  
  333. 1.4.1 Instructions vs. Data
  334. In the first stage of the CPU's operation, the ROM unit feeds directly into the CPU a 30-bit value which corresponds to an
  335. address given to it by the instruction pointer. The CPU's job is to decide what to do with this value. This is where the
  336. difference between data and instructions becomes important. In the C4C 1, data is an 8 bit value that sits in the ROM and
  337. is used by the program through the instruction LOADROM, while the instructions are what the CPU decodes and executes.
  338. Here are the bitfields for instructions and data when they sit in the ROM and are fed into the CPU:
  339.  
  340. Instruction Bitfield:
  341. [11111][xxxx][xxxxxxxx][xxxxxxxx][00000] where IDENT = identifies byte as instruction and INST = which instruction
  342. [IDENT][INST][OPERANDA][OPERANDB][EMPTY]
  343.  
  344. Data Bitfield:
  345. [0000000000000000000000][xxxxxxxx]
  346. [ UNUSED ][ DATA ]
  347.  
  348. As said previously, data is not executed, only instructions, so what happens when the ROM feeds data into the CPU? The CPU
  349. skips over the data, refreshing itself and moving on to the next instruction. I call this mechanism "passing", as the CPU
  350. "passes over" data or anything else that isn't considered an instruction (doesn't contain instruction's identifier in highest
  351. five bits).
  352.  
  353. 1.4.2 Executing an Instruction
  354. The CPU follows several steps to execute an instruction after it is fed in from the ROM. After checking to make sure that the
  355. instruction is an instruction by looking at the highest five bits (the instruction identifier) the CPU moves on to decode the
  356. next four bits. These bits identify which instruction is to be executed. The instruction decoder, when fed these four bits,
  357. selects a location in a special memory unit containing the instruction's microcode. The operands are cached for later in a
  358. special register, the operand register. Now, back to the special memory unit that contains the microcode - the microcode unit.
  359.  
  360. Once the instruction decoder selects the instruction's microcode (see section 1.3.2 for an explanation of what microcode is),
  361. it sequentially executes the microcode, outputing each line of microcode on the bus after shifting and ORing the correct
  362. operand with the output (which operand to select, if any at all, is specified in the selected line of microcode by two bits
  363. at the end). Now, since instructions are stored as a series of microcode sequences, each time a unit returns data and the P signal
  364. to the CPU, the next microcode sequence of the instruction is executed, until the end of the instruction is reached. This is how
  365. the CPU moves through several sequences of microcode to make all the units work together.
  366.  
  367. Since the C4C 1's CPU executes each instruction from a series of microcode sequences ORed with the formatted operands sequentially,
  368. we can't really calculate how long an instruction takes from each pulse of the "clock" that is attached to the top of the
  369. instruction pointer. We need to redefine what a cycle is. Instructions vary in length, and therefore, we will redefine a cycle
  370. as the length of time it takes to execute one line of microcode. This means a simple instruction like MOV might take two cycles,
  371. and a more complex one like ADD 5 or 6.
  372.  
  373. 1.4.3 Operands
  374. As specified in the instruction bitfield, there are two operands in each instruction. These operands are used to change how the
  375. instruction executes - for example, in the MOV instruction, they are used to determine which registers are being copied from
  376. and copied to. They are 8 bit values that can be addresses, or registers. What is missing from operands is the direct storage
  377. of constants. All operands in the C4C 1 are references. This is simply the design of the C4C 1, all data constants are loaded
  378. from the ROM or RAM into registers. This is also due to my laziness in implementing any method to distinguish constants from
  379. references.
  380.  
  381. 1.4.4 Register Operands
  382. One of the operands that a instruction can store is a register. As said in section 1.2.4 (Registers unit), there are 16 registers
  383. (AX - PX). These registers are addressed in a very specific way inside an operand. Since there are only 16 registers, we only need
  384. a 4 bit value to store them. So, inside the operand bitfield, the register bitfield would look like this:
  385.  
  386. [0000][xxxx] where addr = address of register from 0 - 15 (AX - PX)
  387. [NONE][ADDR]
  388.  
  389.  
  390.  
  391. 2. Programming Reference
  392. 2.1 Overview/Intro
  393. This section is not as expansive as the general architecture section, and will go over programming the C4C 1. First, as a review,
  394. we will go over the facilities provided for the programmer by the C4C 1 computer:
  395. - 8 bit architecture - data and addresses and such are 8 bits long - computer is based around 8 bit data
  396. - 256 bytes of ROM
  397. - 256 bytes of RAM
  398. - 16 general purpose registers: AX - PX
  399. - Writeable Instruction Pointer and Conditionals Unit for jumps
  400. - Arithmetic / Logic Unit
  401. - 8 bit I/O port
  402.  
  403. With those facilities in mind, let's take a look at the way instructions and data are stored in 30 bit bytes in the filt ROM:
  404. Instruction Bitfield:
  405. [11111][xxxx][xxxxxxxx][xxxxxxxx][00000] where IDENT = identifies byte as instruction and INST = which instruction
  406. [IDENT][INST][OPERANDA][OPERANDB][EMPTY]
  407.  
  408. Data Bitfield:
  409. [0000000000000000000000][xxxxxxxx]
  410. [ UNUSED ][ DATA ]
  411.  
  412. Register bitfield (for use in operands):
  413. [0000][xxxx] where addr = address of register from 0 - 15 (AX - PX)
  414. [NONE][ADDR]
  415.  
  416. And a assembly instruction corresponding to instructions or data:
  417. Instruction: [MNEMONIC] [OPERANDA], [OPERANDB]
  418.  
  419. Data: DB [8BIT-BYTE]
  420.  
  421. To program the C4C 1 CPU in PowderToy, there are several steps you need to take:
  422. 1. Write out the instruction in assembly mnemonics, e.g. MOV AX, BX
  423. 2. Find the binary address corresponding to the instruction, e.g. 0001 for MOV
  424. 3. Encode the operands in binary, e.g. OPERANDA[AX] becomes 00000000 and OPERANDB[BX] becomes 00000001
  425. 4. Put the instruction together in binary, with the identifier at the front, followed
  426. by the binary instruction address, followed by the operands, and lastly the sequence 00000
  427. e.g. 11111 + 0001 + 00000000 + 00000001 + 00000 => 111110001000000000000000100000
  428. 5. Convert the instruction from binary to hex, e.g. 111110001000000000000000100000 => 0x3E200020
  429. 6. Set the PROP tool to edit CTYPE and paste the hex instruction with the "0x" at the front,
  430. click OK and click on the filt memory cell you want to write to. The cells go from left to right,
  431. then top to bottom. (Address 0 - 15 first row, 16 - 31 second row, and so on until address 255)
  432.  
  433. Putting data into the ROM is similar. Simply convert the 8 bit byte to hex, put the 0x in front of it,
  434. paste it into the PROP tool with it set to CTYPE, and click on the filt memory cell you want to write to.
  435.  
  436. 2.2 Basic Programming
  437. Now that the previous section (2.1) has introduced you to the facilities provided by the C4C 1 and how to program it,
  438. I will just give you all the instructions and the information required to program with them. The instructions are formatted
  439. in a special way. I write the mnemonic of the instruction first, followed by the operands, followed by thier types: either [NONE],
  440. [REGISTER] for register, [ROMADDR] for a ROM address, [RAMADDR] for a RAM address, and [CONSTANT] for constant (used only in DB). The
  441. instruction's value in binary (address) that is used in INST from the instruction bitfield in section 2.1 is listed below this,
  442. followed by the description. Operands A and B correspond to a, b in instruction. Here you go:
  443.  
  444. HLT [NONE]
  445. - Address: 0000
  446. - Stops and resets the CPU
  447.  
  448. MOV a, b [REGISTER],[REGISTER]
  449. - Address: 0001
  450. - Copies the value of register b to register a
  451.  
  452. STORE a, b [RAMADDR], [REGISTER]
  453. - Address: 0010
  454. - Stores contents of register b in RAM memory location a
  455.  
  456. LOADRAM a, b [REGISTER], [RAMADDR]
  457. - Address: 0011
  458. - Loads contents of RAM memory location b into register a
  459.  
  460. LOADROM a, b, [REGISTER], [ROMADDR]
  461. - Address: 0100
  462. - Loads contents of ROM memory location b into register a
  463.  
  464. DB a [CONSTANT]
  465. - Address: None
  466. - This is a special instruction - the value of a is simply stored in the ROM, using the data bitfield talked about in
  467. section 2.1. DB stands for data byte - the instruction stores one 8 bit byte. This data can be retreived using LOADROM,
  468. where the value for the ROM address would be the address of this byte
  469.  
  470. JMP a [ROMADDR]
  471. - Address: 0101
  472. - Changes value of instruction pointer to the value of a - this is an unconditional jump
  473.  
  474. JZ a, b [ROMADDR], [REGISTER]
  475. - Address: 0110
  476. - Changes the value of the instruction pointer to the value of a only if the value of register b is zero - this is a
  477. conditional jump
  478.  
  479. JNZ a, b [ROMADDR], [REGISTER]
  480. - Address: 0111
  481. - Changes the value of the instruction pointer to the value of a only if the value of register b is not zero - this is a
  482. conditional jump
  483.  
  484. OR a, b [REGISTER], [REGISTER]
  485. - Address: 1000
  486. - Performs logical or on values of registers a and b, stores result in register a
  487.  
  488. AND a, b [REGISTER], [REGISTER]
  489. - Address: 1001
  490. - Performs logical and on values of registers a and b, stores result in register a
  491.  
  492. NOT a [REGISTER]
  493. - Address: 1010
  494. - Performs logical not on value stored in register a and stores the value in register a
  495.  
  496. SHL a [REGISTER]
  497. - Address: 1011
  498. - Performs an overflow, destructive left shift on register a
  499.  
  500. SHR a [REGISTER]
  501. - Address: 1100
  502. - Performs an overflow, destructive right shift on register a
  503.  
  504. ADD a, b [REGISTER], [REGISTER]
  505. - Address: 1101
  506. - Adds the values of registers a and b together, stores result in register a
  507.  
  508. RECV a [REGISTER]
  509. - Address: 1110
  510. - Receive a value into register a from the I/O port
  511.  
  512. SEND a [REGISTER]
  513. - Address: 1111
  514. - Send a value from register a to the I/O port
  515.  
  516. 2.3 Advanced Information
  517. This information talks about the instructions on a deeper level. Here, we will talk about the actual execution of each instruction.
  518. This means we get to revisit the microcode sequences from earlier. This is described in detail in section 1.4.2 and 1.3.2.
  519. The following lists every instruction, and the details of how it is executed by the CPU. Each instruction's description is divided into
  520. two parts: the number of cycles it takes to execute, and a detailed description of the microcode behind each cycle. One last note: any
  521. bitfield represented by x's (e.g. [xxxx]) is where operands are ORed with the microcode.
  522.  
  523. - HLT [NONE]
  524. - Number of Cycles: 1
  525. - Execution Information: Special - this is wired directly to CPU components
  526.  
  527. - MOV a, b [REGISTER],[REGISTER]
  528. - Number of Cycles: 2
  529. - Execution Information:
  530. Cycle 1: [0011][xxxx][0000] = Read data of register b, address [xxxx] back to CPU
  531. Cycle 2: [0011][xxxx][0001] = Write data out of CPU onto register a [xxxx]
  532.  
  533. - STORE a, b [RAMADDR], [REGISTER]
  534. - Number of Cycles: 2
  535. - Execution Information:
  536. Cycle 1: [0011][xxxx][0000] = Read data of register b, address [xxxx] back to CPU
  537. Cycle 2: [1][0010][xxxxxxxx] = Write data out of CPU onto RAM address a [xxxxxxxx]
  538.  
  539. - LOADRAM a, b [REGISTER], [RAMADDR]
  540. - Number of Cycles: 2
  541. - Execution Information:
  542. Cycle 1: [0][0010][xxxxxxxx] = Read RAM address b [xxxxxxxx] back to CPU
  543. Cycle 2: [0011][xxxx][0001] = Write data out of CPU onto register a [xxxx]
  544.  
  545. - LOADROM a, b, [REGISTER], [ROMADDR]
  546. - Number of Cycles: 2
  547. - Execution Information:
  548. Cycle 1: [0001][xxxxxxxx] = Read ROM address b [xxxxxxxx] back to CPU
  549. Cycle 2: [0011][xxxx][0001] = Write data out of CPU onto register a [xxxx]
  550.  
  551. - DB a [CONSTANT]
  552. - Number of Cycles: 1
  553. - Execution Information: Special - the CPU uses the "passing" mechanism to skip over this
  554.  
  555. - JMP a [ROMADDR]
  556. - Number of Cycles: 1
  557. - Execution Information:
  558. Cycle 1: [0100][xxxxxxxx] = Write ROM address a out of CPU onto instruction pointer [xxxxxxxx]
  559.  
  560. - JZ a, b [ROMADDR], [REGISTER]
  561. - Number of Cycles: 2
  562. - Execution Information:
  563. Cycle 1: [0011][xxxx][0000] = Read data of register b, address [xxxx] back to CPU
  564. Cycle 2: [0101][xxxxxxxx][1] = Write ROM address a out of CPU into the conditionals unit, data from register b is also
  565. written out in order for the conditionals unit to decide whether to JMP or not
  566.  
  567. - JNZ a, b [ROMADDR], [REGISTER]
  568. - Number of Cycles: 2
  569. - Execution Information:
  570. Cycle 1: [0011][xxxx][0000] = Read data of register b, address [xxxx] back to CPU
  571. Cycle 2: [0101][xxxxxxxx][0] = Write ROM address a out of CPU into the conditionals unit, data from register b is also
  572. written out in order for the conditionals unit to decide whether to JMP or not
  573.  
  574. - OR, AND, NOT, SHL, SHR, ADD a, b [REGISTER], [REGISTER] OR a [REGISTER]
  575. - Number of Cycles: 4
  576. - Special: OR, AND, ADD are a, b [REGISTER], [REGISTER] format while NOT, SHL, and SHR are a [REGISTER] format
  577. - Execution Information:
  578. Cycle 1: [0011][xxxx][0000] = Read data of register b, address [xxxx] back to CPU. For NOT, SHL, and SHR - AX is
  579. read in - but this doesn't influence the execution
  580. Cycle 2: [0111][00000000] = The register specified by b is read into the ALU secondary
  581. Cycle 3: [0011][xxxx][0000] = Read data of register a, address [xxxx] back to CPU.
  582. Cycle 4: [0110][0000][CMND] = Register a is read into ALU accumulator, CMND is the hardcoded number of which operation
  583. to execute (0 - 5, corresponding to OR - ADD)
  584. Cycle 5: [0011][xxxx][0001] = Write data out of CPU onto register a [xxxx]
  585.  
  586. - RECV a [REGISTER]
  587. - Number of Cycles: 2
  588. - Execution Information:
  589. Cycle 1: [1000][00000001] = Request data from peripheral into the CPU
  590. Cycle 2: [0011][xxxx][0001] = Write data onto register a, address [xxxx] from peripheral
  591.  
  592. - SEND a [REGISTER]
  593. - Number of Cycles: 2
  594. - Execution Information:
  595. Cycle 1: [0011][xxxx][0000] = Read data from register a, address [xxxx] back to CPU
  596. Cycle 2: [1000][00000000] = Write loaded data to the peripheral unit
  597.  
  598. 2.4 Example Programs
  599. This section showcases some example programs for the C4C 1 Computer.
  600.  
  601. 2.4.1 Fibonnaci Sequence Program
  602. Address Command Binary Hex Comment
  603. 0 DB 1 000000000000000000000000000001 0x00000001 ;Store the value 1 in memory cell 0
  604. 1 SEND AX 111111111000000000000000000000 0x3FE00000 ;Since all registers are 0 at CPU start, I can output 0
  605. 2 LOADROM AX, 0 111110100000000000000000000000 0x3E800000 ;Load memory cell 0 (a value of 1) into AX
  606. 3 SEND AX 111111111000000000000000000000 0x3FE00000 ;Perform fibbonaci
  607. 4 MOV CX, AX 111110001000000100000000000000 0x3E204000
  608. 5 ADD AX, BX 111111101000000000000000100000 0x3FA00020
  609. 6 MOV CX, BX 111110001000000100000000100000 0x3E204020
  610. 7 SEND AX 111111111000000000000000000000 0x3FE00000 ;Output fibonnaci
  611. 8 JZ 11, AX 111110110000010110000000000000 0x3EC16000 ;Jump to terminate if AX overflows
  612. 9 JMP 4 111110101000001000000000000000 0x3EA08000 ;Jump back to fibonnaci
  613. 10 DB 0xEE 000000000000000000000011101110 0x000000EE ;Store 0xEE
  614. 11 LOADROM AX, 10 111110100000000000000101000000 0x3E800140 ;Retrieve 0xEE
  615. 12 SEND AX 111111111000000000000000000000 0x3FE00000 ;Print "EE" on display, signifies overflow
  616. 13 DB 0 000000000000000000000000000000 0x00000000 ;Why the hell would I want to end my program in addr 13?
  617. 14 HLT 111110000000000000000000000000 0x3E000000 ;Halt
  618.  
  619. 2.4.2 Input/Output
  620. Address Command Binary Hex Comment
  621. 0 RECV BX 111111110000000010000000000000 0x3FC02000 ;Input a number
  622. 1 ADD AX, BX 111111101000000000000000100000 0x3FA00020 ;Add it to AX: AX is intially zero
  623. 2 SEND AX 111111111000000000000000000000 0x3FE00000 ;Output AX
  624. 3 JMP 1 111110101000000010000000000000 0x3EA02000 ;Repeat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement