# Assignment2: RISC-V Toolchain
( Due: Oct 30, 2019 )
## Requirements
1. Following the instructions of [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/@sysprog/rJAufgHYS), pick up two assembly programs from [Assignment1: RISC-V Assembly and Instruction Pipeline](https://hackmd.io/@jserv/By5OE6fOr) and rewrite into C implementations which can execute with [rv32emu](https://github.com/sysprog21/rv32emu).
* You shall not pick up the program(s) submitted by youself already.
* You may pick up the same topic as other students did, but you shall figure out something by your own.
2. Disassemble the ELF files generated by C compiler and compare the assembly listing between handwritten and compiler optimized one.
* You can modify the arguments specified by `RV32I_CFLAGS` to experiment. e.g. Change `-O3` (optimized for speed) to `-Os` (optimized for size).
* Describe your obserations and explain.
* Function calls and `ecall` shall be taken into considerations.
3. Check the results of `emu-rv32i` for the statistics of execution flow and explain the internal counters such as `true_counter`, `true_counter` (crucial for [branch prediction](https://en.wikipedia.org/wiki/Branch_predictor)), `jump_counter`, etc. Then, try to optimize the generated assembly. You shall read [RISC-V Assembly Programmer's Manual](https://github.com/riscv/riscv-asm-manual/blob/master/riscv-asm.md) carefully and modify Makefile in order to append new assembly targets.
* Would you encounter data hazards? Can you do [instruction scheduling](https://en.wikipedia.org/wiki/Instruction_scheduling) manually?
4. Write down your thoughts and progress in [HackMD notes](https://hackmd.io/s/features).
* [Example page](https://hackmd.io/@kksweet8845/2019q3homworkquiz2): Do not modify this note.
* Insert your HackMD notes and programs in the following table.
* 2 entries as expected.
## Fill in the table for your homework
| Name (Chinese/English) | Descriptions | HackMD note | Program (GitHub link) |
| ---------------------- | ------------ | ------------ | --------------------- |
|張家銘 | prime number| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/PV_zFTfQR9Gxb7eap7ME-w?view) | [link]() |
|張家銘 | POW function| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/S8ra4N2UQx2qCEee_Z5nHQ) | [link]() |
|戴宏諺| 9*9 multiplication table | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/@kksweet8845/rsicvlab299multitable)| [github](https://github.com/kksweet8845/adv_CO_lab2)|
|戴宏諺| Recursive binary search| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/@kksweet8845/riscvlab2binarysearchtree)|[github](https://github.com/kksweet8845/adv_CO_lab2)|
| 黃瀚群 | Bubble Sort | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/acLWhdFkT5KUGOylwZDrRQ)
| 黃瀚群 | Permutations(nCk) with recursion |[Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/acLWhdFkT5KUGOylwZDrRQ)
|潘家瑞|POW function| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/mKb05niNQz6-ycOvIbSjxA) | [Github](https://github.com/surajpakhi/ComputerArchitecture/blob/master/MyPowFunction.c)
|潘家瑞|Tower of Hanoi | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/dghEWx3-TuqYzK0dhI-cOw) | [Github](https://github.com/surajpakhi/ComputerArchitecture/blob/master/TowerOFHanoi.c)
| 周沛辰 | Multiplier | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/bl9PKrP0TxivyfOiR-tRtw?view) |[Link](https://github.com/sq0332ppps/Computer-architecture/blob/master/HW2/multiplier.c)
| 周沛辰 | Sort 1~5 With Bubble Sort |[Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/_NbeweMIT2qK92rlAAxfPQ?view)| [Link](https://github.com/sq0332ppps/Computer-architecture/blob/master/HW2/bubblesort.c)
|林家葦|Sum of First N Natural Numbers|[Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/9O3vzqfISvuGDKFqxnwbyQ)|[github](https://github.com/CCUWayen/Computer-Architecture/blob/master/assignment3/test.c)|
林家葦|Multiplier|[Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/u9r9zWxtQ9C5oudDyqRGtA?view)|[github](https://github.com/CCUWayen/Computer-Architecture/blob/master/assignment2/test.c)
|黃俞紘| 9*9 multiplication table| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/YUnbbcqeQI6QTt3_7iT3Cw?view)|[github](https://github.com/YuuuuH/NCKU_computer_architecture/tree/master/hw2)
| 黃偉宸 | Multiplier | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/UiIYXMlKRZmUlCrQQY0Gww) |[github](https://github.com/murumura/risc-v/tree/master/lab2)
| 黃偉宸 | bit reverse |[Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/UiIYXMlKRZmUlCrQQY0Gww) |[github](https://github.com/murumura/risc-v/tree/master/lab2)
| Soonmyun Jang | Catalan number/Multiplier | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/0gUA2-ogTXO4GlCiywknhA) | [Link](https://github.com/JANGSOONMYUN/ComputerArchitecture/tree/master/Assignment2_RISC-V/rv32emu)
| 林聖堯| Bit_reverse, Prime Number | [Assignment2: RISC-V Toolchain](/@_01X9rimQmWH33Djf8QhoA/BJGjBWS9r)|
|王昱翔| bubble sort/binarySearch| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/dv6rfki_SP6h7JCRr49oMA?view)|
|黃俞紘| Hanoi Tower| [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/EoDSavA_QNa2aUnzz5kWtg)|[github](https://github.com/YuuuuH/NCKU_computer_architecture/tree/master/hw2)|
|曾士峰| Lucas Number | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/@xl86305955/rv32i_lucas_number)| [github](https://github.com/xl86305955/rv32emu_C_program/blob/master/lucas.c) |
|曾士峰| Fraction `!` | [Lab2: RISC-V RV32I[MA] emulator with ELF support](https://hackmd.io/@xl86305955/rv32i_frac)| [github](https://github.com/xl86305955/rv32emu_C_program/blob/master/frac.c) |