---
tags: computer-arch
---
# Assignment1: RISC-V Assembly and Instruction Pipeline
> Due: ==Oct 10, 2023==
## Requirements
1. Following the instructions of [Lab1: RV32I Simulator](/@sysprog/H1TpVYMdB), you shall write RISC-V assembly programs ([RV32I](https://en.wikipedia.org/wiki/RISC-V) ISA) and output to the console with environment calls.
* Choose one problem (A, B, or C) from [Quiz1](https://hackmd.io/@sysprog/arch2023-quiz1), translate it from C code to a complete RISC-V assembly program, and include the relevant test data.
* Generate a simplified (but still informative) use case that serves as the subject for your assignment, demonstrating the practical application of the above selected problem (i.e., derived from Problem A/B/C from [Quiz1](https://hackmd.io/@sysprog/arch2023-quiz1)). For instance, you can create a use case that involves performing branchless [counting leading zero](https://en.wikipedia.org/wiki/Leading_zero) operations on integer [base-2 values](https://man7.org/linux/man-pages/man3/log2.3.html) titled as "[Implement log2 with branchless clz](https://graphics.stanford.edu/~seander/bithacks.html)" or "[Matrix multiplication using bfloat16](https://huggingface.co/blog/hf-bitsandbytes-integration)."
* You are required to use only RV32I instructions (without M or F/D extensions) for floating-point data manipulation. This means you should not depend on a C compiler to generate assembly routines; instead, you must write RISC-V assembly code from scratch.
* At least 3 test data should be included in your program(s).
* Without accepting an external data set, you can inline the predefined data.
* Do choose a **unique subject** to work on, as each student should have a separate program. Starting earlier is advised to ensure you have ample time for your work.
* Your program(s) must include loops (or recursive calls) and conditional branches, especially when writing test cases.
* You must demonstrate iterative efforts to enhance the RISC-V programs, including reducing code size and minimizing runtime overhead, with explicit measurements.
* Although **you MUST write down your own RISC-V assembly**, you can still verify the output of the C compiler's assembly output. As a result, you are able to describe the entire program.
* You must ensure that the program functions correctly with the [Ripes](https://github.com/mortbopet/Ripes) simulator.
* Reference: [Example RISC-V Assembly Programs](https://marz.utk.edu/my-courses/cosc230/book/example-risc-v-assembly-programs/)
2. You must provide explanations for both the program's functionality and the operation of each instruction using the [Ripes](https://github.com/mortbopet/Ripes) simulator.
* Using the visualization for signals such as register write/enable signals, multiplexer input selection, and more, describe your application. You must provide examples for each stage, including IF, ID, IE, MEM, and WB. You should also explain the appropriate memory update steps.
3. Write down your thoughts and progress in [HackMD notes](https://hackmd.io/s/features).
* [Example page](https://hackmd.io/@kaeteyaruyo/risc-v-hw1)
> :warning: Do not modify this note.
* Insert your HackMD notes and RISC-V assembly programs in the following table.
* Your HackMD page should be [Published](https://hackmd.io/s/all-about-profile-page) and editable as [Signed-in write](https://hackmd.io/@codimd/note-permission).
* **Write in English** and feel free to utilize ChatGPT or [QuillBot](https://quillbot.com/) to improve your writing.
## Fill in the table for your homework
> :warning: Be aware of spaces. Separate each item with ==` | `==
| Formal given name | Descriptions | HackMD note | Program (GitHub/gist hyperlink) |
| ----------------- | ------------ | ----------- | ------------------------------- |
| Sample0 | Palindrome Linked List | [Lab1: RV32I Assembly](https://hackmd.io/@kdnvt/2022-arch-hw1) | [Palindrome Linked List](https://github.com/kdnvt/Palindrome-linked-list/) |
| Sample1 | Patching Array | [Lab1: RV32I Assembly](https://hackmd.io/@7y4UQB2gRoSQRw5iAm-5lw/r1__oMEHY) | [Patching Array](https://github.com/chinghongfang/ComputerArchitecture/tree/main/hw1) |
| Sample2 | Shuffle the Array | [Lab1: RV32I Assembly](https://hackmd.io/@wIVnCcUaTouAktrkMVLEMA/ryqv60zHK) | [Shuffle the Array](https://gist.github.com/tobychui/032db06f31c7b72be1df5b30ab8d937c) |
| Sample3 | Three Consecutive Odds | [Lab1: RV32I Assembly](https://hackmd.io/@wanghanchi/BkM-53UWi) | [Three Consecutive Odds](https://github.com/WangHanChi/2022_Computer_Architecture) |
| 黃柏叡 | Logarithm of bfloat16 numbers | [Lab1: RV32I Assembly](https://hackmd.io/@coding-ray/2023-ca-hw-1) | [Logarithm of bfloat16 numbers](https://github.com/coding-ray/2023-ca-hw-1) |
| 陸品潔 | Implementation of Bit-Plane Slicing with CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@GliAmanti/BJlxAv651a) | [Implementation of Bit-Plane Slicing with CLZ](https://github.com/GliAmanti/ComputerArchitecture_HW1) |
| 唐飴苹 | Calculate the Hamming Distance using Counting Leading Zeros | [Lab1: RV32I Assembly](https://hackmd.io/@O6C2C3zQQBanDM55QRZ7DQ/Lab1_RV32I_assembly) | [Calculate the Hamming Distance using Counting Leading Zeros](https://github.com/yptang5488/Computer-Architecture) |
| 劉庭聿 | Approximating a bfloat number using binary search | [Lab1: RV32I Assembly](https://hackmd.io/@JY7VQTBOSN-L5160WDDdmQ/SJw8t_6ea) | [Approximating a bfloat number using binary search](https://github.com/timothyliu0912/computer_architecture/tree/main/Assignment1) |
| 洪佑杭 | Multiplication overflow prediction for unsigned int using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@hungyuhang/risc-v-hw1) | [Multiplication Overflow Prediction](https://github.com/hungyuhang/computer_architecture_2023/tree/main/hw1) |
| 陳金諄 | Output different number with same binary format by using counting leading zeros | [Lab1: RV32I Assembly](https://hackmd.io/@david96514/SJkY51yx6) | [Output different number with same binary format by using counting leading zeros](https://github.com/david965154/computer_architecture_hw) |
| 陳浩文 | Implement palindrome detection and using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@DpuBXDwLSDCIE6cNJSjUlg/HyQ2i4nep) | [Implement palindrome detection and using CLZ](https://github.com/padaray/computer_architecture_hw1) |
| 侯廷翰 | Optimizing Storage with Count Leading Zero | [Lab1: RV32I Assembly](https://hackmd.io/@M1Il4baLQwe1hoqHMQez_g/ry9_38Wg6) | [Optimizing Storage with Count Leading Zero](https://github.com/tinhanho/Assignment1-RISC-V-Assembly-and-Instruction-Pipeline) |
| 廖泓博+ | Matrix multiplication with floating point addition and multiplication | [Lab1: RV32I Assembly](https://hackmd.io/@kc71486/computer_architecture_hw1) | [Matrix multiplication with floating point addition and multiplication](https://github.com/kc71486/Computer-Architecture/blob/main/hw1/) |
| 蔡忠翰 | Convert FP32 to BF16 and Count the Number of Ones in the Binary Representation | [Lab1: RV32I Assembly](https://hackmd.io/@n-g2ouCxQbmy_er1MvIKhQ/rkCz0Wega) | [Convert FP32 to BF16 and Count the Number of Ones in the Binary Representation](https://github.com/jeremy90307/Computer_Architecture) |
| 林允顥 | Implement Variable Byte Compression By Counting Leading Zeros | [Lab1: RV32I Assembly](https://hackmd.io/@fewletter/CAHW1) | [Implement Variable Byte Compression By Counting Leading Zeros](https://github.com/fewletter/CAHW/tree/main/HW1) |
| 戴鈞彥 | Get sine value without floating point multiplication support | [Lab1: RV32I Assembly](https://hackmd.io/@ranvd/computer-arch-hw1) | [Get sine value without floating point multiplication support](https://github.com/ranvd/ComputerArch/tree/main/hw1) |
| 張澤家+ | Improving multiplication without extension instruction | [Lab1: RV32I Assembly](https://hackmd.io/@NeedSleep/computer-arch-hw1) | [riscv-multiplicator-no-mul-instruction](https://github.com/HotMercury/riscv-multiplicator-no-mul-instruction) | - |
| 洪胤勛 | Implement log base power of 2 with CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@KXkA4u0LQuyNTwOorDw2RA/HJSryZ4g6) | [log base power of 2 with clz](https://github.com/eeeXun/computer_architecture/tree/master/hw1) |
| 李承泰 | Find the position of MSB by CLZ |[Lab1: RV32I Assembly](https://hackmd.io/@-plyrukoRemmLd0FT8Qy3A/SkbtANuJ6) | [Find the position of MSB by CLZ](https://github.com/Iann2000/computer_architecture_hw1)|
| 施柏安 | Implementing FP32 Operations by Applying FP32 to Bfloat16 Conversion Algorithm | [Lab1: RV32I Assembly](https://hackmd.io/@-8re6JcGROuLo7EfIU6Vsw/H19WZtTJp) |[Implementing FP32 Operations by Applying FP32 to Bfloat16 Conversion Algorithm](https://github.com/brian049/2023_Computer_Architecture/tree/main/HW1)|
| 陳川曜 | Find Leftmost 0-byte using CLZ |[Lab1: RV32I Assembly](https://hackmd.io/@cychen/computer_architecture_hw1) | [Find Leftmost 0-byte using CLZ](https://github.com/hugo0406/Computer-Architecture/tree/main/hw1) |
| 謝維倫 | Enhancing Buffer Overflow Defense with Return Address Protection and CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@VCNgJgo3RCyrEhvI9NKLUQ/Sk0aAbxea)| [Enhancing Buffer Overflow Defense with Return Address Protection and CLZ](https://github.com/weiweiwei68/RISC-V-Assembly-and-Instruction-Pipeline) |
| 曾鼎棊 | Implement counting tailing zero by CLZ | - | - |
| 李晨瑞 | Implement next power of two using clz | [Lab1: RV32I Assembly](https://hackmd.io/@terry23304/2023-arch-assignment1)| [Implement next power of two using clz](https://github.com/terry23304/next-power-of-2-with-clz) |
| 邱德昌 | Determining the Maximum Value by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@yayaoh/By7B-QKlT) | [determining the maximum value by CLZ](https://github.com/dcciou/2023-computer-structure-hw1) |
| 林柏全 | Find First String of 1-bits of a Given Length by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/fcLwVbDrQ--hS-a9NgSQBw?view) | [Finding First String of 1-bits of a given length by CLZ](https://github.com/chuan0306/Computer-Architecture-Homework-1) |
| 劉智恩 | Sum of Leading Zeros in Linked List by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@chihenliu/Sum_of_Leading_Zeros_in_LinkedList_by_CLZ) | [Sum of Leading Zeros in Linked List by CLZ](https://github.com/chihen0709/Computer_Architecture_lab1/tree/main) |
| 林昊霆 | Counting total zero of binary number by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@TBL/HkIq-TGxp) | [Counting total zero of binary number by CLZ](https://github.com/andy891023/Computer_architecture_2023/tree/master) |
| 林以薰 | Indexing of hierachical data structures by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@scones525/computer_architecture_hw1) | [Indexing of hierachical data structures by CLZ](https://github.com/scones525/Computer-Architecture-2023Fall_NCKU/tree/main/hw1) |
| 盧俊銘 | Compare difference between fp32 multiplication and bf16 multiplication | [Lab1: RV32I Assembly](https://hackmd.io/@jimmylu0303/assignment-1) | [Compare difference between fp32 multiplication and bf16 multiplication](https://github.com/jimmylu890303/2023_Computer_Architecture/tree/main/assignment/hw1) |
| 鍾沅熹 | Multiply a floating-point by an integer | [Lab1: RV32I Assembly](https://hackmd.io/@freshLiver/2023-arch-hw1) | [Multiply a floating-point by an integer](https://gist.github.com/freshLiver/1b2300a91d466a7f2cc0a78b53fa5075) |
| 黃于睿 | Generate 3×3 Filter Box in BF16 Format and Application | [Lab1: RV32I Assembly](https://hackmd.io/@DarrenHuang0411/CA_as1) | [Generate 3×3 Filter Box in BF16 Format and Application](https://github.com/DarrenHuang0411/NCKU_CA_2023/tree/Assignment-1) |
| 范紘維+ | A Novel Approach to IP Routing: CLZ for Prefix Match | [Lab1: RV32I Assembly](https://hackmd.io/@gV8IONkMS_a6aHt20QNuAg/S1OSux_ga) | [A Novel Approach to IP Routing: CLZ for Prefix Match](https://github.com/fan1071221/Computer_Architecture_2023_hw1) |
| 江冠霆 | Normalizing a value using clz | [Lab1: RV32I Assembly](https://hackmd.io/@VBHMCAcXSo2j5UzcTBAQZQ/Bkxtnhilp) | [Normalizing a value using clz](https://github.com/HenryChaing/Computer_Arch_112) |
| 李冠澄 | Optimize the multiplication of 3 integer numbers without extensions | [Lab1: RV32I Assembly](https://hackmd.io/@j2MyJwXxSyCtQi-KVu4CKQ/CA-NCKU-Guan-assignment1/edit) | [Optimize the multiplication of 3 integer numbers without extensions](https://github.com/Kuanch/ComputerArchitecture2023Fall_NCKU/tree/main/hw1) |
| 陳彥佑 | Implement unsigned int mul by count leading zero | [Lab1: RV32I Assembly](https://hackmd.io/@yAB_kQtlST6mqZV2uCHm3Q/ByhYzQhga) | [Implement unsigned int mul by count leading zero](https://github.com/y0y0alex/CA/tree/main/homework1) |
| 張偉治 | Implement backpropagation algorithm using bfloat16 floating-point format | [Lab1: RV32I Assembly](https://hackmd.io/@nfUUgsYRTGy81y5d9AYOyg/r1Oy_iLga) | [Implement backpropagation algorithm using bfloat16 floating-point format](https://github.com/AgainTW/b16-SIMD) |
| 洪碩星 | Implement transformation from integer to float by clz | [Lab1: RV32I Assembly](https://hackmd.io/@shhung/HkLDYvfea) | [Implement transformation from integer to float](https://github.com/shhung/Implement-transformation-from-integer-to-float) |
| 魏泳禎 | Implement and analyze BF16 multiplication | [Lab1: RV32I Assembly](https://hackmd.io/@qOvjgDvTQrGZGAlv5oHqsA/BkCWpJ3g6) | [Implement and analyze BF16 multiplication](https://github.com/aa860630/2023-computer-architecture/tree/main/HW1) |
| 陳冠元 | Implement function to find maximum absolute value in bfloat16 array for quantization | [Lab1: RV32I Assembly](https://hackmd.io/@K1NCVjKnTCmNaikFb4gt-A/B1Fj-TGWp) | [Implement find bf16 maximum absolute value](https://github.com/KuanYuan0530/Computer_Architecture_2023/) |
| 林勁羽 | Implement image binarization by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@edenlin/CompArchi_HW1) | [Binarization by CLZ](https://github.com/JinYu1225/2023_Computer_Architecture) |
| 李熙堃 | Improve bitwise and of numbers range with clz | [Lab1: RV32I Assembly](https://hackmd.io/@JoshuaLee0321/asm-fall-2023) | [Improve bitwise and of numbers range with clz](https://github.com/JoshuaLee0321/fall-2023-computer-arch/tree/main/lab1%20RISC-V%20instruction%20and%20pipeline) |
| 高紹捷 | Implement square root using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@F3cNkb4bSWKg00J7O-_y8w/rJvzACwgT) | [Implement square root using CLZ](https://github.com/kkkkk1109/Implement-square-root-using-CLZ)|
| 施宇庭 | Exploiting data-level parallelism in bfloat16 multiplication with SWAR | [Lab1: RV32I Assembly](https://hackmd.io/@yutingshih/arch2023-homework1) | [Exploiting data-level parallelism in bfloat16 multiplication with SWAR](https://github.com/yutingshih/ca2023-hw1) |
| 吳堉銨 | Data encryption using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@c3WNnG7RRK2J17ifSiezZA/H1jhh2t6n) | [Data encryption using CLZ](https://github.com/kk908676/ComputerArchitecture.git) |
| 鄭博文 | Reducing memory usage with bfloat16 and bfloat16 multiplication | [Lab1: RV32I Assembly](https://hackmd.io/@PWCheng/CAHW01) | [Reducing memory usage with bfloat16 and bfloat16 multiplication](https://github.com/BrianCheng-TheLegend/2023_ComputerArchitecture/tree/main/Hw01) |
| 王豊惟 | Linear convolution using bfloat16 | [Lab1: RV32I Assembly](https://hackmd.io/@mlFpoYoxSjevnbdVLdrijw/r1IehUGxp) | [Linear convolution using bfloat16](https://github.com/st10740/Computer-Architecture-HW/tree/main/HW1) |
| 王昱傑 | implement maxpool operator using bfloat16 | [Lab1: RV32I Assembly](https://hackmd.io/v-Ojsy9YSbm3fOHANHPH5g) | [implement maxpool operator using bfloat16](https://github.com/pine0113/bf16-maxpool) |
| 黃定山 | A comparison of binary search, Harley’s algorithm, and De Bruijn sequence in the context of CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@ShanHuang/r1rGEIula) | [Comparison of binary search and hash tables in the context of CLZ](https://github.com/Sun970053/Computer_Architecture) |
| 鄭朝駿 | Perform a one-hot encoding search using the count leading zeros function | [Lab1: RV32I Assembly](https://hackmd.io/@J7GZnFx3Qe-HPvOgHWEQsg/SyXb5pHeT) | [Perform a one-hot encoding search using the count leading zeros function](https://github.com/ChengChaoChun/computer_architecture)|
| 魏彥庭 | Matrix multiplication using bfloat16 | [Lab1: RV32I Assembly](https://hackmd.io/@HKWg9_3IT2aEDv2v6T-Z0Q/SJb0JeVg6) | [Martrix multiplication using bfloat16](https://github.com/Terry7Wei7/bf16) |
| 許唯萱 | Explore and analysis different approaches of CLZ method | [Lab1: RV32I Assembly](https://hackmd.io/@Cg0dDRWsTdK_B3tu0eo_lQ/BkMr6idg6) | [Explore and analysis different approaches of CLZ method](https://github.com/weishiuan1120/computer_architecture/tree/master) |
| 倪英智 | Implement priority encoder using CLZ |[Lab1: RV32I Assembly](https://hackmd.io/@NIYINGCHIH/BkvgNE3e6) | [Implement priority encoder using CLZ](https://github.com/ollieni/2023-Computer-Architecture) |
| 楊宇翔 | Calculate the log2 Integer part of a log2 int64 number by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@5HlvW0J1QTmqg6azf_URYQ/HJKitfYx6) | [Calculate the Integer part of a log2 int64 number by CLZ](https://github.com/Hsiang0528/Computer-Architecture) |
| 林子勝 | converting float to integer | [Lab1: RV32I Assembly](https://hackmd.io/FG3n3lD9Sf2xi85CsdyFog) | [Computer_Architecture_11201_homework_1](https://github.com/raphael89918/Computer_Architecture_11201/tree/main/homework_1) |
| 顏伯丞 | Determine number size range by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@QtzWvn_wQCicLQ65E_OREQ/risc-v-hw1) | [Determine number size range by CLZ](https://github.com/spadee27357/Computer-Architecture) |
| 鄭吉廷 | Implement Collatz conjecture by ctz | [Lab1: RV32I Assembly](https://hackmd.io/@2ytPc3wiSXuOhkj2eWyplA/rksqSjAea) | [Implement Collatz conjecture by ctz](https://github.com/ChengChiTing/Computer_Architecture/tree/master/Homework_1) |
| 林晉宇 | Image scaling with Bilinear interpolation by float32 multiplication | [Lab1: RV32I Assembly](https://hackmd.io/@linyu0425/SJHkb8lWT) | [Image scaling with Bilinear interpolation](https://github.com/linyu425/ComputerArchitecture/tree/main/hw1) |
| 陳燦仁 | Shell sort with FP32 in BF16 format | [Lab1: RV32I Assembly](https://hackmd.io/@EKxqXpsYSvqseqCzNyYK1w/S1CVeW3gp) | [Shell sort with FP32 in BF16 format](https://github.com/TRChen11011/Shell-sort-with-FP32-in-BF16-format) |
| 李亮穎 | Implement unsigned int multiplication by CLZ without multiplication instruction | [Lab1: RV32I Assembly](https://hackmd.io/@LLL00/rJ49csPgT) | [Implement unsigned int multiplication by CLZ without multiplication instruction](https://github.com/YaRu056/2023_Computuer_architecture) |
| 張正德 | Convert RGB image into grayscale by using RV32I ISA | [Lab1: RV32I Assembly](https://hackmd.io/@gofzKoaiTI6mFzp4FTuenw/HJg3Q-lb6) | [Convert RGB image into grayscale by using RV32I ISA](https://github.com/00853029/Computer_Architecture/tree/main/hw1) |
| 周育晨 | Generate bitmask by CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@8G9q08Y6Tnq9OJMgzCV1TA/By_CTTYgT) | [Generate bitmask by CLZ](https://github.com/yuchen0620/Computer-Architecture/tree/main/HW1) |
| 許卜元 | Optimizing division with powers of two using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@byuan/SyuBihl-p) | [Optimizing division with powers of two using CLZ](https://github.com/PuYuanHsu/Optimizing-division-with-powers-of-two-using-CLZ) |
| 簡志耀 | Convolution by using bfloat16 | [Lab1: RV32I Assembly](https://hackmd.io/@RayqVUcSSOiX_pVJKh0DLg/ryRgUK-Wp) | [Convolution by using bfloat16](https://github.com/Yao1201/Convolution-by-using-bfloat16) |
| 彭煜博 | Reverse bits using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@normal/bit-reversal-clz) | [Reverse bits using CLZ](https://github.com/paulpeng-popo/ComputerArchitecture/tree/main/hw1) |
| 丁竟烽 | Find Longest String of 1-Bits using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@Paintako/Computer_Architecture_hw1) | [Find Longest String of 1-Bits using CLZ](https://github.com/Paintako/Computer_Organization) |
| 蕭明祥 | Find first set using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@TXKjP2SFR8O-nS9pbDQAjw/B1pLJMeZ6) | [Find first set using CLZ](https://github.com/CSIE523/2023_Computer_Architecture_FALL/tree/main/hw1) |
| 劉誠量 | Find first Clear using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/wbhmiFeBS1OUxeyWX14LpA?view) | [Find first Clear bit using CLZ](https://github.com/LCL-cdsak/Computer-Architecture/tree/main/hw1) | |
| 張智惟 | Bits Compression Using CLZ | [Lab1: RV32I Assembly](https://hackmd.io/@scottgood333/SkM6KdVMT) | [Bits Compression Using CLZ](https://github.com/scottgood333/computer_architecture/tree/main/hw1) |
| 李協儒 | Implement Exponential-Golomb coding by using clz |[Lab1: RV32I Assembly](https://hackmd.io/@DotandLog/2023ca_hw1) | [Implement Exponential-Golomb decoding by using clz](?) |
> :warning: Be aware of spaces. Separate each item with ==` | `==