ScratchData LogoScratchData
Back to khang2009's profile

Computer Builder

KHkhang2009•Created January 4, 2024
Computer Builder
4
4
561 views
View on Scratch

Instructions

This project is really technical so it's hard to dive in, but I will try my best to describe it: Editing controls: - Space: Edit a value at an address in the initial memory (every value in the memory is in the range 0-255 inclusive, which is represented as a byte, which has an address in the range 0-255, *not* in the Scratch standard which is 1-256) - R: Reset this project - Z: Export the initial memory - X: Import the initial memory - /: Activate the CPU and enter the running state How the execution works: First, the memory is loaded based on the initial memory. The CPU program counter initializes to address 0. For every cycle of the CPU, it fetches the opcode byte at the address of the program counter, and it subsequently fetches 2 bytes of data at 2 subsequent addresses; then the CPU executes differently for each opcode (go to 'List of opcodes' section for more detail). After that, the CPU increases the program counter by 3. Running controls: Space: Performs a cycle and increments the CPU clock, if the automation slider is enabled (in other words, whether the 'program: automated running?' slider equals 1) 'program: cycles per tick' slider: If the automation slider is enabled, it decides the number of cycles performed in a single tick. I: Types input and sets the input at address 240 and sets 1 at address 241 Green flag: Returns to editing mode List of opcodes: (A$B = A*16+B) Each line has a syntax of "a$b = n: OPCODE [address/data/ignored 1] [address/data/ignored 2]: details...", where n is the opcode in bytes, OPCODE is the opcode's name, and the 2 square brackets are the instruction data bytes fetched by the CPU. 0$0 = 0: MOV [address 1] [address 2]: Move value from address 1 to address 2 0$1 = 1: INC [address 1] [ignored 2]: Increment and modify the value at address 1 0$2 = 2: DEC [address 1] [ignored 2]: Decrement and modify the value at address 1 0$3 = 3: SET [address 1] [data 2]: Set the value at address 1 to value 2 1$0 = 16: CMP [address 1] [address 2]: Compare two values at two addresses. If they are equal, set the compare flag to 0. If otherwise value 1 is larger, set the compare flag to 1. Otherwise, set the compare flag to 0. 1$1 = 17: ADD [address 1] [address 2]: Add two values together at both addresses, then set the result to address 1 1$2 = 18: SUB [address 1] [address 2]: Subtract two values together at both addresses, then set the result to address 1 1$3 = 19: MUL [address 1] [address 2]: Multiply two values together at both addresses, then set the result to address 1 1$4 = 20: DIV [address 1] [address 2]: Floor-divide two values together at both addresses, then set the result to address 1 2$0= 32: AND [address 1] [address 2]: Perform the AND operation on two values at both addresses, then set the result to address 1 2$1 = 33: OR [address 1] [address 2]: Perform the OR operation on two values at both addresses, then set the result to address 1 2$2 = 34: NOT [address 1] [ignored 2]: Perform the NOT operation on value at address 1, then set the result at the address 2$3 = 35: XOR [address 1] [address 2]: Perform the XOR operation on two values at both addresses, then set the result to address 1 3$1 = 48: JUMP [address 1] [ignored 2]: Set the program counter to the address indicated by the value at address 1. 3$2 = 49: JCZ [address 1] [ignored 2]: Set the program counter to the address indicated by the value at address 1 if the compare flag equals 0. 3$3 = 50: JCP [address 1] [ignored 2]: Set the program counter to the address indicated by the value at address 1 if the compare flag equals 1. 3$4 = 51: JCN [address 1] [ignored 2]: Set the program counter to the address indicated by the value at address 1 if the compare flag equals -1. 4$0 = 64: OUT [address 1] [ignored 2]: Deliver the output as a value at address 1. 15$15 = 255: HLT [ignored 1] [ignored 2]: Halt the CPU

Description

Here is a simple memory code to import: ʣɣʃʈɣʃĭāɣā˄ʃɫʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃǥʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃʃ Also, the thumbnail, https://www.flickr.com/photos/56207859@N05/10071538156 by Craighton Miller is licensed under CC BY 2.0. To view a copy of this license, visit https://creativecommons.org/licenses/by/2.0/.

Project Details

Project ID946524734
CreatedJanuary 4, 2024
Last ModifiedJanuary 6, 2024
SharedJanuary 4, 2024
Visibilityvisible
CommentsAllowed