---
tags: computer-arch
---
# Assignment1: RISC-V Assembly and Instruction Pipeline
> Due: ==Oct 25, 2021==
## 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.
* Select one of the problems listed at [LeetCode](https://leetcode.com/problemset/all/). Difficuty "Easy" is preferable.
* Don't implement the same problem as others do. Your program shall be different.
* Your program(s) MUST contain loops (or recursive calls) and conditional branches.
* You can check the assembly output from C compiler, but **you should write down RISC-V assembly by your own**. Thus, you are able to explain the whole program.
* You have to ensure the program fully functioned with [Ripes](https://github.com/mortbopet/Ripes) simulator.
2. You have to explain how each instruction works along with [Ripes](https://github.com/mortbopet/Ripes) simulator.
* Explain your program with the visualization for multiplexer input selection, register write/enable signals and more. You have to illustrate each stage such as IF, ID, IE, MEM, and WB. In addition, you should discuss the steps of memory updates accordingly.
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.
* Of course, you MUST write in English.
## Fill in the table for your homework
| Formal given name | Descriptions | HackMD note | Program (GitHub link) |
|:-----:| --- | --- | --- |
| Sample1 | Single number II ([LeetCode 137](https://leetcode.com/problems/single-number-ii/)) | [Lab1: RV32I Simulator](https://hackmd.io/@eecheng/HJojUvdrw) | [singleNumber](https://gist.github.com/eecheng87/7063130a1ca057a1288540c956589ce9) |
| Sample2 | Count Leading Zeros | [Lab1: RV32I Simulator](https://hackmd.io/@WeiCheng14159/rkUifs2Hw) | [Count Leading Zeros](https://github.com/WeiCheng14159/ncku_ca_hw1) |
| Sample3 | Dot Product | [Lab1: RV32I Simulator](https://hackmd.io/@kaeteyaruyo/risc-v-hw1) | [Dot Product](https://github.com/kaeteyaruyo/Computer-Architecture/tree/master/hw1) |
| Sample4 | MergeSort | [Lab1: RV32I Simulator](https://hackmd.io/@waynelinbo/rJpBUiu8P) | [MergeSort](https://github.com/waynelinbo/Computer_Architecture_Lab1_MergeSort) |
| 方竫泓^+^ | Patching Array ([LeetCode330](https://leetcode.com/problems/patching-array/)) | [Lab1: RV32I Simulator](https://hackmd.io/@7y4UQB2gRoSQRw5iAm-5lw/r1__oMEHY) | [Patching Array](https://github.com/chinghongfang/ComputerArchitecture/tree/main/hw1) |
| 陳亮州^+^ | Peak Index in a Mountain Array ([LeetCode 852](https://leetcode.com/problems/peak-index-in-a-mountain-array/)) | [Lab1: RV32I Simulator](https://hackmd.io/@choucl/ByY9fP3rK)| [Peak index](https://github.com/choucl/computer_architecture/tree/master/hw1_riscv_asm) |
| 彭恩宇 | Ugly Number ([LeetCode 263](https://leetcode.com/problems/ugly-number/)) | [Lab1: RV32I Simulator](https://hackmd.io/@PongEnYu/HJx72-TrF) | [Ugly Number](https://github.com/kkk080808/Computer_Architecture_hw1) |
| 徐卓朗 | Shuffle the Array ([LeetCode 1470](https://leetcode.com/problems/shuffle-the-array/)) | [Lab1: RV32I Simulator](https://hackmd.io/@wIVnCcUaTouAktrkMVLEMA/ryqv60zHK) | [Shuffle the Array](https://gist.github.com/tobychui/032db06f31c7b72be1df5b30ab8d937c) |
| 鍾震 | Reverse Bits ([LeetCode 190](https://leetcode.com/problems/reverse-bits/?fbclid=IwAR087HCHbWdpLnySM_ifVjgX1OTeObSRv_QNLZ7bvIGzaGQgS6sLj-d9akw)) |[Lab1: RV32I Simulator](https://hackmd.io/@Japoka/HJvFHdLBF) | [Reverse Bits](https://github.com/japoka410666/Computer-Architecture-Assignment1) |
| 向景亘 | Counting Bits ([LeetCode 338](https://leetcode.com/problems/counting-bits/)) | [Lab1: RV32I Simulator](https://hackmd.io/@oscarshiang/arch_hw1) | [Counting Bits](https://github.com/OscarShiang/ComputerArchHW/tree/main/hw1) |
| 李仲恩 | TwoSum ([LeetCode 1](https://leetcode.com/problems/two-sum/)) | [Lab1: RV32I Simulator](https://hackmd.io/@IVUP6rGJQAmUMyQytt73_g/Hkr7EhUBK) |[Two Sum](https://github.com/chungen0126/TwoSum) |
| 陳力維 | Pascal's Triangle II ([LeetCode 119](https://leetcode.com/problems/pascals-triangle-ii/)) |[Lab1: RV32I Simulator](https://hackmd.io/bt0v-sK8TfaEPWzxQn4pBA?view) |[Pascal's Triangle II](https://github.com/newyear2580/computer_architecture_hw1/tree/main) |
| 鄭學陽 | Number of 1 Bits ([LeetCode 191](https://leetcode.com/problems/number-of-1-bits/)) | [Lab1: RV32I Simulator](https://hackmd.io/jj61kCP_R-etsz4c7KTOSw)|[Number of 1 bits](https://github.com/xueyang0312/computer_architecture_hw1) |
| 陳韋綸 | Find Numbers with Even Number of Digits ([LeetCode 1295](https://leetcode.com/problems/find-numbers-with-even-number-of-digits/))|[Lab1: RV32I simulator](https://hackmd.io/@_UHs74UQS7uNne9_7SwQFQ/SyoJM_Lrt)|[Find Numbers with Even Number of Digits](https://github.com/alan-chen1412/Computer_Architecture/blob/main/Find%20Numbers%20with%20Even%20Number%20of%20Digits/Find%20Numbers%20with%20Even%20Number%20of%20Digits.s)|
| 黃瑋盛 | Palindrome Number ([LeetCode 9](https://leetcode.com/problems/palindrome-number/)) |[Lab1: RV32I simulator](https://hackmd.io/@N9qHU_eLRvKyfDfJk8cDXA/Bk3xctfBF) |[Palindrome Number](https://github.com/wilsonhshs/Assignment1-RISC-V-Assembly-and-Instruction-Pipeline) |
| 歐禮寬 | Plus One ([LeetCode 66](https://leetcode.com/problems/plus-one/))|[Lab1: RV32I Simulator](https://hackmd.io/@tUe5KoeuTLGibjG22HLtdg/BJRenN-8K) | [Plus One](https://github.com/Korin777/Computer-Architecture/tree/main/hw1) |
| 林甄羚 | Roman to Integer ([LeetCode 13](https://leetcode.com/problems/roman-to-integer/)) |[Lab1: RV32I simulator](https://hackmd.io/@9s5oiDBGQVmyEWDpvMhHtw/BkpBqJNHt) |[RomanToInteger](https://github.com/amberlin0516/LeetCode13_RomanToInteger) |
| 許永貞 | Find the Highest Altitude ([LeetCode 1732](https://leetcode.com/problems/find-the-highest-altitude/)) | [Lab1: RV32I simulator](https://hackmd.io/@SRepqiofRCqX0QTL2aUCvA/SkmLc5RHt) | [Find the Highest Altitude](https://github.com/a12345645/Computer-Architecture/tree/main/hw1) |
| 劉恩澔 | Search Insert Position ([LeetCode 35](https://leetcode.com/problems/search-insert-position/))|[Lab1: RV32I simulator](https://hackmd.io/WrAQ6uwsSM-hPBVsOaAZSA?view)|[Search Insert Position](https://github.com/geniuseric/Computer_Architecture/tree/master/HW1)|
| 李政憲 | Sqrt(x) ([LeetCode 69](https://leetcode.com/problems/sqrtx/))|[Lab1: RV32I simulator](https://hackmd.io/@30vhEV7FQECcWeCF1eAN5A/ry44_j8rK)|[Sqrt(x)](https://gist.github.com/garyparrot/780da2ae0783d101160a1d433054c660)|
| 張又仁 | Defuse the Bomb ([Leecode 1652](https://leetcode.com/problems/defuse-the-bomb/)) | [Lab1: RV32I Simulator](https://hackmd.io/@arthur-chang/S1AM0D8Ht)|[Defuse the Bomb](https://github.com/arthurchang09/Computer_Architecture/tree/main/hw1)
| 朱俊霖 | Find Smallest Letter Greater Than Target ([Leetcode 744](https://leetcode.com/problems/find-smallest-letter-greater-than-target/))|[Lab1: RV32I simulator](https://hackmd.io/@chu0809/ca_hw1) | [Find Smallest Letter Greater Than Target](https://github.com/reputation0809/ca_hw1) |
| 陳銘畯 | Move Zeroes ([Leetcode 283](https://leetcode.com/problems/move-zeroes/))|[Lab1: RV32I simulator](https://hackmd.io/@CRbocq-NR46M5LnNvliy7g/rJb57RKNF)|[Move Zeroes](https://github.com/MingJun0609/Computer-Architecture/tree/main/hw1)
| 孫祥鈞 | Maximum Subarray ([Leetcode 53](https://leetcode.com/problems/maximum-subarray/)) | [Lab1: RV32I simulator](https://hackmd.io/@dvN7aRjsRqGwO0cEOTkAfQ/SyMdBQPSF) | [Maximum Subarray](https://github.com/qoo332001/Computer-Architecture/tree/main/homework1) |
|蕭又瑜 |Two Sum II - Input array is sorted ([Leetcode 167](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/))|[Lab1: RV32I simulator](https://hackmd.io/@ZIzxQXHdQDyZ0z_jDKUflw/Hydc-i0BF)|[Two Sum II - Input array is sorted](https://github.com/yuyuranium/ComputerArchitecture/tree/main/hw1) |
| 莊崴 | Add Binary ([Leetcode 67 ](https://leetcode.com/problems/add-binary/)) | [Lab1: RV32I Simulator](https://hackmd.io/414ZvPsQSw6Y1fVQX028xA?both)| [Add Binary](https://github.com/AirysTW/Add-Binary-Leetcode-67-) |
| 賴虓翰 | N-Repeated Element in Size 2N Array ([LeetCode 961](https://leetcode.com/problems/n-repeated-element-in-size-2n-array/)) | [Lab1: RV32I Simulator](https://hackmd.io/@E4b6eQ9-RWSAX-9mP_FLhA/B1KTHywHK) |[N-Repeated Element in Size 2N Array](https://github.com/xiaohan484/RISC-V-practice) |
| 林信宇 | Longest Palindrome ([LeetCode 409](https://leetcode.com/problems/longest-palindrome/))|[Lab1: RV32I Simulator](https://hackmd.io/@axwl03/r11t81wBY) | [Longest Palindrome](https://github.com/axwl03/Arch-2021/tree/main/hw1) |
| 黃品程 | Power of Four ([LeetCode 342](https://leetcode.com/problems/power-of-four/)) | [Lab1: RV32I Simulator](https://hackmd.io/@Pin-Cheng/r1U3mW-IF)|[Power of Four](https://github.com/benson7633769/RISCV_project)|
| 蕭珮珊 | Length of Last Word ([LeetCode 58](https://leetcode.com/problems/length-of-last-word/))|[Lab1:RV32I Simulator](https://hackmd.io/@peishan/Hy5WwjCrK) | [Length of Last Word](https://github.com/Peishan3/CA_Assignment_1)
| 李安豐 | Missing Number ([LeetCode 268](https://leetcode.com/problems/missing-number/)) |[Lab1:RV32I Simulator](https://hackmd.io/@AnfongLee/Bki5_MZLY) | [Missing Number](https://github.com/anfong-query/Leetcode268-missing_number) |
| 王駿瀚 | Matrix Diagonal Sum ([LeetCode 1572](https://leetcode.com/problems/matrix-diagonal-sum/)) |[Lab1:RV32I Simulator](https://hackmd.io/@pDHgQQB5SCSMkKl0dbQvDw/By2PK-WUF) |[Matrix Diagonal Sum](https://github.com/jumha/Computer_Architecture_HW1) |
| 陳昕佑 | Min Cost Climbing Stairs ([Leetcode 746](https://leetcode.com/problems/min-cost-climbing-stairs/)) | [Lab1: RV321 Simulator](https://hackmd.io/@A_KUyU-fSfqgFIepPOCwcQ/BJTHB4XBK) | [Min Cost Climbing Stairs](https://github.com/zoanana990/Computer_Architecture/tree/main/CA_HW01) |
|黃上睿| Binary Number with Alternating Bits ([Leetcode 693](https://leetcode.com/problems/binary-number-with-alternating-bits/)) | [Lab1: RV32I Simulator](https://hackmd.io/@2Fd91KW6RO-0boxmOPqGSQ/ByhoaUtBF)|[Binary Number with Alternating Bits](https://github.com/shangrex/Homework/tree/master/computer_architecture/hw1)|
|陳日昇|Sort an Array ([LeetCode 912](https://leetcode.com/problems/sort-an-array/))|[Lab1: RV32I Simulator](https://hackmd.io/@Wc9buHGHRaudUz3D5Dp_FA/SJCq3LsSF/edit)|[Sort an Array](https://github.com/Risheng1128/Computer-Architecture/tree/main/HW1)|
|張峻瑋|single number ([LeetCode 136](https://leetcode.com/problems/single-number/))|[Lab1: RV32I simulator](https://hackmd.io/@F7GGdY_NSxe2XlypzW57AA/ryzCosRHK)|[Single number](https://github.com/Seeyoutomato/RISCV_project.git)|
|朱祐均|Best Time to Buy and Sell Stock ([LeetCode 121](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/))|[Lab1: RV32I simulator](https://hackmd.io/@vuJ_c2nYTM2v6lZwDtjajg/B140b0f8Y)|[Best Time to Buy and Sell Stock](https://github.com/timtdsas/2021_CA_assignment)|
|李其祐|Majority Element ([Leetcode 169](https://leetcode.com/problems/majority-element/))|[Lab1: RV32I simulator](https://hackmd.io/@jackli/CA_hw1)|[Majority Element](https://github.com/Chi-you/NCKU_CA/tree/main/hw1)|
|戴仕誠| Climbing Stairs ([Leetcode 70](https://leetcode.com/problems/climbing-stairs/))|[Lab1: RV32I simulator](https://hackmd.io/@WHKhZ7rvSTCx6LNmPBploQ/HJQdSBTBK)|[Climbing Stairs](https://github.com/tai010034/2021_Fall_COMPUTER_ARCHITECTURE_HW1)
|杰凱力艾| Happy Number ([Leetcode 202](https://leetcode.com/problems/happy-number/))|[Lab1: RV32I simulator](https://hackmd.io/HGoYFkqURaysSGstrs9FwQ?view)|[Happy Number](https://github.com/jakariaaa27/2021_Fall_COMPUTER_ARCHITECTURE_HW1)|
|林嘉歆| Power of Three ([Leetcode 326](https://leetcode.com/problems/power-of-three/))|[Lab1: RV32I simulator](https://hackmd.io/@DAuS-TwtQl27wzt5g4o1NQ/BJWdNrlIY)|[Power of Three](https://github.com/cindy1217lin/Computer_Architecture_hw1)|
|黃牧恩| Bitwise AND of Numbers Range ([Leetcode 201](https://leetcode.com/problems/bitwise-and-of-numbers-range/))|[Lab1: RV32I simulator](https://hackmd.io/@huang-me/computerArch_LAB1)|[Bitwise and in range](https://github.com/huang-me/BitwiseAndInRange.git)|
|歐子杰|N-th Tribonacci Number ([LeetCode 1137](https://leetcode.com/problems/n-th-tribonacci-number/))|[Assignment1](https://hackmd.io/@oucs638/computer-arch-2021-fall-assignment1)|[Tribonacci Number](https://github.com/oucs638/CA_2021_FALL/tree/main/Assignment1)|
|陳明吉|Hamming Distance ([LeetCode 461](https://leetcode.com/problems/hamming-distance/))|[Lab1: RV32I simulator](/_gFpDYgLQg6YVvTMU2zy-Q)|[Hamming Distance](https://github.com/mingjii/Computer_Architecture/tree/master/HW1)|
|郭又宗|Number Complement ([Leetcode 476](https://leetcode.com/problems/number-complement/) )|[Lab1: RV32I Simulator](https://hackmd.io/@kuouu/2021-arch-homework1)|[Number Complement](https://github.com/erickuo5124/computer_architecture/tree/hw1)|
|伍志忠|Monotonic Array[(LeetCode 896)](https://leetcode.com/problems/monotonic-array/)|[Lab1: RV32I Simulator](https://hackmd.io/RsUL8sFgTEqJ2Q3wbZvyFg?view)|[Monotonic Array](https://github.com/cicero884/Computer_architecture_2021/tree/main/hw1)
| 朱育萱 | Find the difference ([LeetCode 389](https://leetcode.com/problems/find-the-difference/))|[Lab1:RV32I simulator](https://hackmd.io/aOtKyEctTx65Sr96vm6tdw?both)|[Find the difference](https://github.com/OliveLake/findTheDifference)|
| 張亦妤 | Power of Two ([LeetCode 231](https://leetcode.com/problems/power-of-two/))|[Lab1: RV32I Simulator](https://hackmd.io/@Evelyn-Jhang/rJj28N6BK)|[Power of Two](https://github.com/tako861225/power-of-two)|
| 劉品宏 | Add Digits[(Leetcode 258)](https://leetcode.com/problems/add-digits/)|[Lab1:RV32I Simulator](https://hackmd.io/7wQTJKarTaOaKkErF1D5Uw?view)|[Add Digits](https://github.com/momoph46/Computer-Architecture)
| 鄭力維^+^ | Perfect Number ([Leetcode 507](https://leetcode.com/problems/perfect-number/))|[Lab1:RV32I Simulator](https://hackmd.io/nKckoINtQkCw-GTjfqJKqQ)|[Perfect Number](https://github.com/Welly0902/ComputerArchitectureHW/tree/main/Perfect%20Number)
| 鄒柏宇 | Valid Perfect Square([Leetcode 367](https://leetcode.com/problems/valid-perfect-square/))|[Lab1:RV32I Simulator](https://hackmd.io/6juDh8EDS267BJ7Bwy1pRg)|[Valid Perfect Square](https://github.com/gfrank1688/ca_hw1)
| 張力尹 | Sort Colors([Leetcode75](https://leetcode.com/problems/sort-colors/))|[Lab1:RV32I Simulator](https://hackmd.io/ZwAmFgXdTzSwIt1u5osvhQ?view)|[sort colors](https://github.com/liing0228/computer-hw/blob/main/hw1/)|
| 陳柏瑋 | Fruit Into Baskets([Leetcode 0904](https://leetcode.com/problems/fruit-into-baskets/))|[Lab1: RV32I Simulator](https://hackmd.io/vik__vwBScOIJC1P7JI0eg?view)|[Fruit Into Baskets](https://github.com/abnormal749/ComputerArchHW/tree/main/hw1)
| 羅紹豪 | Fibonacci Number ([Leetcode 509](https://leetcode.com/problems/fibonacci-number/)) | [Lab1:RV32I Simulator](https://hackmd.io/C5ktHPP-Tf2Hjj3SNOM1Yw?both) | [Fibonacci number](https://github.com/airpodspro/computr-architecture) |
| 柯凱瑋 | Find Peak Element ([Leetcode 162](https://leetcode.com/problems/find-peak-element/)) |[Lab1:RV32I Simulator](https://hackmd.io/@k-w-k/HJX88MWUK) |[Find Peak Element](https://github.com/kaiweike/ComputerArchitecture/tree/main/hw1)|
| 譚亦翔^+^ | Reverse String ([Leetcode344](https://leetcode.com/problems/reverse-string/))|[Lab1:RV32I Simulator](https://hackmd.io/@pt2JoPc6SNCdX7cvPan6_Q/ByRUaNQ8Y)|[Reverse string](https://github.com/ppolokisstw/reverse-string)|
| 林劭謙^+^ | Perfect Number ([Leetcode 507](https://leetcode.com/problems/perfect-number/)) |[Lab1:RV32I Simulator](https://hackmd.io/qF4BZmjYTAWsytsB7kU7ng)|[Perfect Number](https://github.com/BipDaDip/ComputerArchitecture/tree/main/hw1)|