---
# System prepended metadata

title: Assignment 4

---

# Assignment 4
**Name:** &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;***M Akash***
**Roll No.:** &nbsp;&nbsp;&nbsp; ***CS22B037***


>## Development of a Ternary Computer System Utilizing Alien Transistor Technology


### 1. **Ternary Logic Operations:**
Ternary Logic Systems operate with three states (0, 1, and 2), unlike binary systems which use only two states (0 and 1). The ternary logic will encompass both arithmetic and logical operations, broadening the computational spectrum and potentially increasing computational efficiency and speed. In this, we take 2 as undefined value.
For Instruction Set Architecture, it will have arithmetic operations like ADD, SUB, MUL and bitwise operators like AND, OR, XOR, NOT and logical operators like AND, OR, NOT.
**++*NOTE:*++** If we get output as undef, then we consider that value as one of the input given else user will be given the choice to select based on convenience else 2 is considered as NULL pointer (for addresses).
- ++Arithmetic Operations-++
1. To add two ternary numbers, we use *ADD* you line them up by their least significant digit (rightmost digit) and add column by column, just like in decimal addition. If a column has 2, then it's sum with other will also be undefined.
eg. 1212 + 1101=10212 (Since 2+1=2(undef), 1+0=1, 1+1=10)
2. Subtraction in ternary involves borrowing, similar to decimal subtraction. When the top digit is smaller than the bottom digit in a column, you need to borrow from the next left column. We use *SUB* for this. When we encounter 2, it's undefined.
eg. 1111 - 1202=0212 (2-1=2 since undefined)
3. Ternary multiplication is similar to decimal multiplication. Multiply each digit of one number by each digit of the other number, and add the results, aligning them according to their place values. We use *MUL* for this.
eg. 102 * 2=222 (2 is undef)

- ++Bitwise Operations-++
1. For *AND*, 0&0=0, 0&1=0, 0&2=2, 1&1=1, 1&2=2, 2&2=2
Since 2 is undefined, so it's bitwise outputs will also be undefined.
2. For *OR*, 0|0=0, 0|1=1, 0|2=2, 1|1=1, 1|2=2, 2|2=2
This rule set is designed to reflect the maximum of two digits, mirroring the logical inclusiveness of the binary OR operation.
3. For *NOT*, !0=1, !1=0, !2=2
Not of undef is undef only
- ++Logical Operations-++
1. 0&&0 is false, 0&&1 is true, 0&&2 and 1&&2 is undef (i.e., 2), so the output can't be decided if we get 2. It's also called And Ternary Ambiguity.
2. 0\||1 is true, 0\||0 is false, 0||2 is undef, output can't be said. It's also called Or Ternary Ambiguity.

This forms the ISA of the Ternary computer System.

---
### 2. **Instruction Encoding:**
Encoding instructions in a ternary system will use trits instead of bits. The main advantage here is a denser encoding scheme.
- ++Trit-based opcode design:++ Larger opcodes are possible within fewer trits, allowing for a broader set of instructions.
- ++Immediate and address values:++ Utilization of ternary digits to increase the data held within the same length of instruction words.
- ++Efficiency:++ Ternary encoding could potentially be more efficient in terms of the width of instructions due to the higher base, which allows more information to be stored per "trit" compared to a bit.
- ++Error Detection:++ By treating "2" as an error state or an undefined state, the system can use this for error detection. Any occurrence of "2" in data could be used to trigger error handling routines.
- ++Control Flow:++ Similar to a NULL pointer in traditional programming, "2" could be used to manage control flows or conditional operations, signaling situations where typical binary decisions are insufficient.

---
### 3. **Pipeline Architecture:**
Since "2" is undefined in this model, effectively the system operates much like a binary system. Each pipeline stage in this modified ternary (effectively binary) system could handle only digits "0" and "1". 
- ++Instruction Fetch (IF):++ This stage fetches instructions from memory. The undefined status of "2" could be used to indicate a memory fault or an invalid instruction location.
- ++Instruction Decode (ID):++ Decodes the fetched instruction into opcode and operands. If "2" appears in the opcode or operands, it could signal an error or a special operation, like an interrupt or a specific control command, given its undefined status.
- ++Execute (EX):++ Carries out the operation dictated by the opcode. If the operation involves arithmetic or logic that results in a "2", this might either trigger an error or might user be given choice to select valid output, if it's not feasible then an input will be the output.
- ++Memory Access (MEM):++ Accesses memory if required by the instruction. If "2" is used in addressing (which should not be normal), it would likely points to NULL pointer.
- ++Write Back (WB):++ Writes the result of the execution back to the register file. Again, any result that tries to write a "2" might not write anything, instead NULL will be initialized.

---
### 4. **Address Range and Capacity:**

Implementing a fully utilized ternary addressing system, where all three digits (0, 1, and 2) are used, each address digit (trit) can hold one of three possible states. This increases the addressable space exponentially compared to binary systems with the same number of address digits.
In a ternary system, the addressable memory is calculated as  $3^n$ , where n is the number of trits (ternary digits) used in the address. This formula gives the total number of unique addresses that can be generated.
- ++Physical Size:++ The physical realization of ternary memory might be more complex. This complexity arises because each memory cell must reliably switch between three distinct states, which might require potentially larger circuit designs than binary cells.
- ++Density:++ The increase in addressability might still lead to a higher overall memory density. For example, where a binary system might need 20 bits to address a million locations (1,048,576 addresses), a ternary system could do this with just 13 trits (1,594,323 addresses), leading to a more compact representation of large address spaces.
- ++Access Times:++ Accessing a ternary memory might be slower than binary due to the more complex decision logic required to distinguish among three states instead of two. However, advancements in ternary logic design and materials technology could mitigate these differences.

---
### 5. **Memory Organization:**
Unlike binary systems where each cell traditionally stores a bit (0 or 1), each ternary memory cell would need to store a trit (0, 1, or 2). This necessitates more complex cell designs.
- ++Using Heap:++ Dynamic Memory Allocation- The heap is used for allocating and deallocating memory dynamically. This includes objects, arrays, or any variable-sized data that outlives the function call it was created in. Heaps manage free memory in a fragmented but efficient manner, allowing for variable allocation sizes and durations.
- ++Multi-Level Cells (MLC):++ Similar to how some flash memory works by storing more than one bit per cell, ternary cells could use multiple voltage levels or other properties to store three distinct states.
- ++Error Checking:++ Given the multiple states, more sophisticated error checking and correction (ECC) methods might be necessary to ensure data integrity.

---