In: Computer Science
1.a. RISC-V has several addressing modes. Describe 4 addressing modes. For each, describe what it does and give an example assembly instruction that uses that addressing mode. b. Starting with a C source code file, describe the steps that must occur in order to actually begin executing the program on your computer.
1.a) RISC V - reduced instruction set computer principles based open standard instruction set architecture. It is an open source licensed design. RISC follows a load-store architecture. It has the bit patterns used to simplify the multiplexers in CPU. RISC V has 32 integer registers and have 32 floating point registers. It is designed to increase computer speed, and reduces cost and power usage. Memory is addressed as 8 bit bytes. it is the minimal set of instructions which leads to many lines of code.
In RISC V there are several addressing modes. The addressing mode defines the way to specify an operand in assembly language program. The four basic addressing modes are:
1. Register
Operand is in a register. It can be direct or indirect
eg: Add R1,R2 which means R1 is added with R2 and result is stored in R1.(direct)
ADD R1,(R2) means R1<---- R1+memory(R2)
add $s1, $s2, $s3 $s1 = $s2+$s3
2. Immediate
Operand is specified in the instruction itself. constants are encoded in the instruction itself.
Add R2, #5 , R2 is added with direct value 5 and result is stored in R2.
eg: addi $ s1, $s2, 10 $s1= $s2 + 10
3. Displacement
Operand is in memory and it is calculated as Base + Offset.
Add R3, 100(R2), R3 <--- R3 + memory(100+R2)
eg: load word, lw $s1, 100($s2) $s1= memory (100+$s2)
4. PC-Relative
Operand is in memory and the address is calculated as PC + Offset . It is used for branch instructions
branch R2 <R1,1500
beq $s1 , $s2, 25 If ($s1== $s2) then goto PC + 4 + 100
1.b) A program is written in a language , and it is saved using its extension then it becomes a source code file .It is executed by the system only, when it is converted into an object code which follows a number of steps and linked with library to form an executable file. C program is a high level language which is converted into machine language for execution.
A program written in C language is saved .c extension. It is the source code and it is compiled to check if there any errors and also it is converted into an object file. Then this object file is linked with library functions to form an .exe file which is executable.
Eg: set.c (source file/code)---------> set.obj (object file/code) --------------> set.exe (executable file)
There are four steps when a program is converted to an executable file ,they are
1. preprocessing
* comments are removed
* macros and include files are expanded
* conditional compilation
stored as intermediate file , set.c becomes set.i
2. compilation
set.i (preprocessed file ) becomes set.s(intermediate compiled output file) which contains assembly level instructions.
3. assembly
set.s becomes set.o by the assembler which contains machine level instructions. this is the object code which contains only the existing code
4. linking
set.o becomes set.exe which contains all the linked functions and libraries.