Building Memory With Logic Gates

We’ll store it so that the instruction set corresponds with the memory address we want to perform the operation on.The Data RAM array and Code RAM arraySo, now we have two RAM arrays that correspond at memory addresses with the instruction we want to perform on specific pieces of data..What we would need to do is iterate over both arrays simultaneously, performing the required instruction on each piece of data as we move along it.Let’s solve the second problem now..I’m going to use a hack to solve this problem because we’re sticking with 8-bit numbers in this post..I’m going to use the largest three binary numbers possible with 8-bits to represent the instruction set of: Load, Add and Store respectively.Note: This is not how it is done in CODE..By this point in the book, Charles Petzold has introduced the concept of a hexadecimal system..He seems to use hexadecimal numbers to represent the instruction set..I want to avoid bringing up hexadecimal numbers in this post, so I’ll stick to 8-bit binary.So, here is the instruction set and their corresponding binary representation.Load: 11111101 (253)Add: 11111110 (254)Store: 11111111 (255)Great!.It seems like we’ve solved both our problems..Let’s represent our data and code RAM arrays in JavaScript now.First, we’re going to get rid of the IIFE’s we had earlier that represented a level triggered latch..I’ll use JavaScript maps to store both RAM arrays..I’m doing this to make the code simpler, and I’m replacing the JS object with a Map because a Map preserves key order.const dataMap = new Map([["000", "00000001"],["001", "00000001"],["010", "00000001"],["011", "00000001"],["100", "00000001"],["101", "00000001"],["110", "00000111"],["111", "00000001"]]);const codeMap = new Map([["000", "11111101"],["001", "11111110"],["010", "11111110"],["011", "11111110"],["100", "11111111"],["101", "11111101"],["110", "11111110"],["111", "11111111"]]);Now, we can just iterate over the maps for the code and data respectively.Iterating over a map is easy, you use Map.entries()We need a way to figure out what to do depending on what instruction set we come across..A simple switch case statement will take care of that.I’ll show you what I’ve built to explain memory iteration using D3.js in the form of a gif here.Memory Iteration GIFThe div on the right represents our accumulator.. More details

Leave a Reply