https://github.com/natelapak/risc-v_decoder
Website that converts a binary or hexadecimal number into its RISC-V Instruction and vice versa
https://github.com/natelapak/risc-v_decoder
assembly react risc-v tailwindcss typescript
Last synced: 3 months ago
JSON representation
Website that converts a binary or hexadecimal number into its RISC-V Instruction and vice versa
- Host: GitHub
- URL: https://github.com/natelapak/risc-v_decoder
- Owner: NateLapak
- Created: 2025-02-14T05:56:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-05T05:18:29.000Z (over 1 year ago)
- Last Synced: 2025-03-05T06:25:02.504Z (over 1 year ago)
- Topics: assembly, react, risc-v, tailwindcss, typescript
- Language: TypeScript
- Homepage:
- Size: 140 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RISC-V Decoder Website
This website converts a hexadecimal or binary number into a RISC-V Assembly instruction.
After taking CMPUT 229, I thought this would be
a good project to practice Typescript and RISC-V instruction conversion.
## Algorithm to decode instruction
Here is the algorithm I used to convert a binary or hex number to its RISC-V Instruction
1. Extract binary or hex number inputted by user
2. Determine opcode by extracting the lowest 6 bits of the 32-bit instruction
3. Using the opcode, determine the instruction type (I-Type, R-Type, S-type, etc)
4. Determine mnemonic of instruction by using funct3 and funct7 of instruction
5. Translate decimal representation of registers to register name
6. If instruction uses an immediate, combine parts to form the full immediate
7. If immediate is negative, use Two's complement to convert
8. Return resulting RISC-V Instruction and output it to user
## Algorithm to encode instruction
Here is the algorithm I used to convert a RISC-V instruction into its hexadecimal number
1. Extract RISC-V Instruction inputted by user
2. Split user input into 3 parts: The mnemonic, the registers, and the immediate (if applicable)
2. Using the instruction's mnemonic, determine its opcode, funct3 and funct7.
3. Translate the register name to its decimal representation
4. Convert the immediate of instruction to binary
5. If immediate is negative, use two's complement.
6. Combine the opcode, funct3, funct7, registers, and immediate into 8 hexadecimal characters.
7. Return resulting hexadecimal number and output it to user
## Testing decode and encode functions
Unit tests were done to ensure the correctness of the encode and decode functions in convert.ts. This was done using ts-jest, a Javascript or Typescript testing framework.
Tests are saved in the tests folder, found in /src/tests.
To run the unit test, use npm test.
## Tech stack
List of programming languages and technolgies used
- HTML/CSS
- Typescript
- NextJS
- TailwindCSS
- Jest
I decided to use Typescript to make translating assembly instructions type consistent.
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.