? Assembler and Virtual Machine for a 16-bit URISC CPU ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
💀

Assembler and Virtual Machine for a 16-bit URISC CPU

Submitted
Updated
Author
amihart
Public Key
Q33N4DHS
Min. Compat.
All
Rating
7 votes
Description The R313 is a (currently) imaginary URISC CPU created by me for educational purposes. URISC stands for "ultimate reduced instruction set", it is a computer with only one instruction. Since it only has one instruction, you do not even need to store the instruction in memory, only the operand of it. The R313 is based on the reverse-subtract and skip-on-borrow (RSSB) instruction (view the README for how this works). It has one operand and is Turing complete. This program contains two programs called "RASM" and "RVM". RASM is the assembler. Included is a "Hello, World!" assembly program to help you understand how it works. RVM is the virtual machine. It will run your code. Please note that I had designed this CPU architecture a long time ago for educational purposes. Coding for this CPU is very difficult and rather impractical. However the virtual machine and assembler that come with this are both fully documented to serve as a guide for assembler and emulation creation. This was originally written in C and then ported to SmileBASIC. You can check out the assembly "Hello, World!" code on PC here Update 1:
  1. Bug fixes.
  2. Modified the text input to act like it does on Windows/Unix.
  3. Added another example file. It asks you for your name, lets you input a name (maximum 3 characters), and then says, "Hello, {name}!"
Categories
Keywords
20 Comment(s) Shelly Shelly I'm confused. You claim this CPU was created by you, but the RSSB URISC concept has been around since 2003. What exactly is original here? 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website The CPU amihart amihart If you continued reading the description and didn't stop there, it mentions "The R313 is based on the reverse-subtract and skip-on-borrow (RSSB) instruction", hence, it is based on an RSSB machine, it is a specific implementation of RSSB but is not RSSB in of itself. There is no copyright to RSSB, I can create whatever I want out of it. R313 is RSSB with some modifications, programs written for generic RSSB may or may not run in R313 depending on the implementation* and R313 programs will simply not run on a generic RSSB machines**. R313 is also refers to a suite of software (virtual machine + assembler + Rebec) and R313 will eventually be a physical CPU (this is a long-term project). RSSB is a very vague concept of how to design a URISC CPU and R313 is a very specific and well-defined implementation of it with specific several modifications to make it more suitable to actually be used practically.*** This question to me seems as silly as if someone wrote a program that can draw circles and you posted a comment saying, "you claim these circles were created by you, but circles have been around since the medieval times!" Like, yeah, I didn't invent RSSB, nor did I invent CPUs, nor did I invent assemblers or virtual machines. This is my specific implementation of many different ideas. R313 is part of a large suite of software I've been working on for awhile here. This includes an assembly and virtual machine both written in C, as well as a programming language called Rebec that compiles to machine code for the R313 specifically, this compiler is written in C as well. One of the many benefits of pursuing a machine like this is the fact that the virtual machine is so incredibly easy to port that porting software would be a breeze, so for fun I've been porting the virtual machine to various platforms (SmileBASIC and TI-84+ for example). That's the only reason this exists. I currently don't have much posted about the progress of the physical CPU because it's been slow due to time and cost constraints but I've already written a lot of the driver software in Rebec. Here you can see an example of a driver for an 8x8 matrix display here. It compiles to machine code for the R313. If you check the source code of the "NAME.RBC" program within the SmileBASIC program on this page, you will notice it is full of labels with "REBEC" in the title, as that program was written in Rebec and not by hand. R313 is a lot more than simply "an RSSB machine". Because "RSSB" is very vague and doesn't describe any precise implementation. This is a very precise implementation. * RSSB requires memory mapping for inputs and outputs, and how these memory mapped operations are handled are not well-defined. I've scoured the internet and found only a couple examples of people making RSSB virtual machines, and they always handled the output mapping in a way I disagree with, so I have altered this in R313. This prevents some implementations of RSSB from working in R313. (Effectively, they make "rssb out" a "special case" where the CPU does not perform RSSB and simply outputs the accumulator. If you look up "hello, world!" in RSSB, you can find only 1 example code online, and it only works based on this assumption. In R313, all instructions perform the rssb, there is no special cases, the CPU always performs RSSB every cycle.) ** R313's memory mapping is different from most implementations and also includes unique memory mapping. "OUT" and "IN" memory maps are moved, and "ONE", "POS", "NEG", and "ROM" are also included (the first three were included to make coding in assembly more intuitive and to make the Rebec compiler more efficient, and "ROM" was added for future compatibility purposes, so that software can know what version of a CPU it is running on and accordingly, assuming I actually get this project to the point of shipping out multiple versions of this CPU). The behavior of "OUT" and "IN" are also explicitly defined, as these are not well-defined generally for RSSB and differ from implementation. OUT and IN are supposed to map to 16 pin each physical data lines on the CPU and these values are refreshed at the end of each clock cycle (the CPU writes the data stored in OUT to the 16 output pins and reads the input pins into IN). *** R313 is very specifically a 16-bit signed URISC CPU based on RSSB with 8 words of memory mapped RAM at addresses 0-7 that are defined in the documentation. Again, RSSB is generic, you could implement it as signed, unsigned, 8-bit, 16-bit, 32-bit, you could adjust the memory mapping however you want, and when it comes to actually building the hardware, the possibilities are pretty endless in how you actually implement RSSB. Shelly Shelly I know this wouldn't be anything like an SB cpu, but an FPGA in SmileBASIC would be insanely cool, even if it just had a few hundred slices. amihart amihart I actually own an FPGA although I'm not even sure how to use it. I went to the manufacturer’s website (Intel) and they want $50-$150 dollars just for the software to program on it... I paid $9 for this thing LOL Until I learn to use FPGAs I won't be able to write a simulator for them since I don't actually know how they work... ninjagnu ninjagnu @amihart there's this really cool talk on FPGAs I watched once. It's from https://media.ccc.de/ I think. Krondelo Krondelo Awesome work, thanks for this! Now lets just hope I can actually understand it and learn a thing or two. ninjagnu ninjagnu Why not get rid of RSSB prefix before things? If all you need is the arguments? amihart amihart Looks nicer that way imo. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself Why not use ' for comments like SB? It looks better in the editor. You could make it another option and leave in the "original" comment character for compatibility. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website That's just an annoying thing to deal with. The code wouldn't be compatible with other versions of the assembler, and plus, basically every assembly language uses ; for comments. snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself I haven't looked too far into it, but I'm convinced with a few basic tweaks, you can implement 90% (or more) of an assembler in SB using just a COMMON DEF library. You'd be limited in features and syntax, I guess, but it's a possibility because many assembly languages are so simple. Using ' for comments is one step towards this. randomous randomous Owner Robot Hidden Easter Eggs Second Year My account is over 2 years old Website Drawing I like to draw! Hobbies Ah cool! I hope people learn stuff from this! ninjagnu ninjagnu So basically rasm is a version of the MOVfuscator but in SB :P amihart amihart I've never heard of the MOVfuscator until now, but looking into it, they are definitely very different. The MOV instruction on an x86 machine just so happens to be Turing-complete in of itself. The MOVfuscator uses this to compile C code into native x86 code only using this single instruction. The differences are as follows:
  1. The MOVfuscator compiles code specifically to run on an x86 chip natively. It does not contain a virtual machine as it is intended to run on your actual hardware.
  2. The MOVfuscator uses "MOV" logic and not "RSSB" logic.
  3. The MOVfuscator compiles from C code while this currently only compiles from assembly code. I don't believe the MOVfuscator contains an assembler because it's meant to be assembled using a native assembler.
12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website I believe that the FIX16 function can be replaced with N<<16>>16. Additionally, single characters of a string can be accessed using square brackets rather than MID$. Also I think your sorting function could be written as something like: DIM LENS[LEN(STN$)] FOR I=0 TO LEN(STN$)-1 LENS[I]=LEN(STN$[I]) NEXT SORT LENS,STN$,STV 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website Oh, a few more things. SB has logical and/or operators (the standard && ||), and you can compare strings using < >= etc. amihart amihart Does using "&&" instead of "AND" have any effect on performance? 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website If the first value is false, it doesn't have to evaluate the second value. (And the opposite for ||) snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself It's just generally more sane to use the right operator for the job. Bitwise AND/OR have to do more work, but it's just more clear to use the logical/conditional operators to people reading your code. Two bonuses in one.