work sheet for week 2: RISC-V assembly language programming using this page https://www.cp.eng.chula.ac.th/~prabhas//teaching/comparch/2024/Programming-RISC-V-assembly.htm 1) run the following assembly programs in venus, observe the result. Check that the result is correct. 1.1 move data from register to register write your answer, what is the value in register x3 when program terminate? addi x2,x0,11 add x3,x2,x0 1.2 move data from register to/from memory write your answer, what is the value in memory 0x104 when program terminate? addi x5,x0,0x11 # set x5 to 0x11 sw x5, 0x100(x0) # store at address 0x100 lw x6, 0x100(x0) # get from mem addi x6,x6,1 sw x6, 0x104(x0) # store to mem 0x104 1.3 simple arithmetic, write the answer what is the value of memory at 0x100 when the program terminate? lw x5, 0x104(x0) # get b lw x6, 0x108(x0) # get c add x4, x5, x6 sw x4, 0x100(x0) # store to a 1.4 accessing an array data using offset, base address points to the beginning of the array ax[20] ax starts at 0x100 base address, size 20 bytes to get an element at ax[1], each element is 32-bit let x3 -index, x4 -base, x5 -effective address, x6 -value addi x3,x0,4 # offset to index 1, 4 bytes addi x4,x0,0x100 # base add x5,x3,x4 # compute effective address lw x6,0(x5) # get from memory write your answer, what is the value of the effective address? 1.5 loop run the following program, what is the value of x3 when the program terminate? addi x3,x0,0 # i = 0 addi x4,x0,10 # const 10 loop: bge x3,x4, exit addi x3,x3,1 j loop exit: 2) compiling high level language to assembly language using "Compiler Explorer" (godbolt.org) input language is C, output language is "RISC_V rv32gc clang" compile and explain the output assembly code (no need to run) 2.1 simple one line program int main(){ int a; a = 11; } 2.2 program with if..then int main(){ int a,b; if(a > 0){ b = 22; } }