Computer Architecture lab2
Computer Architecture lab2
Lab -1
Student’s Name
Roll No.
Date Performed
Marks Obtained
1|Page
Spring 2025 CA Lab-1
Document History
Rev. Date Comment Author
1.0 24/02/2025 Initial draft Engr. Majid Ali
Instructions
Read the manual carefully before start of any tasks / experiments.
Objectives
By the end of this lab, students will be able to learn about
2|Page
Spring 2025 CA Lab-1
Arithmetic Instructions
Arithmetic instructions in RISC-V assembly are used to perform mathematical operations on
data stored in registers. Common arithmetic operations include addition, subtraction,
multiplication, and division. These instructions manipulate integer values and are fundamental
to many programming tasks.
Logical Instructions
Logical instructions perform bitwise operations on data in registers. These operations include
AND, OR, XOR, and NOT, allowing programmers to manipulate individual bits within a data
word. Logical instructions are essential for tasks such as masking, setting, and clearing specific
bits.
3|Page
Spring 2025 CA Lab-1
Ripes Introduction
Ripes is an educational RISC-V simulator designed to facilitate the understanding and learning
of computer architecture and assembly programming. It provides an intuitive graphical interface
that allows users to visualize and interact with the execution of RISC-V assembly programs.
4|Page
Spring 2025 CA Lab-1
Lab Tasks
5|Page
Spring 2025 CA Lab-1
Task-1
Launch the Ripes simulator on your computer.
Select “New Program” to start a new project.
Load the code assembly code into the code editor
Select Processor Type “Single Cycle Processor”.
Run the Program.
Check the Value in Register x23.
Code:
.text
addi x20, x0, 10 # store immidiately by adding value of x0 (0) and 10 and in the x20
addi x21, x0, 0 # store immidiately by adding value of x0 (0) and 0 and in the x21
addi x22, x0, 20 # store immidiately by adding x0 and 20 in x22
sub x23, x20, x22 # store by subtracting x22 from x20 values in x23
Output:
Execution Information:
Explanation:
This code initializes registers x20, x21, and x22 with the values 10, 0, and 20 respectively.
It then computes the difference between x20 and x22, storing the result in register x23.
6|Page
Spring 2025 CA Lab-1
Task-2: Implement assembly code in editor and show what value is appearing at the given
address used in the code in the memory.
Code:
.text
addi x18, x0, 2 # store immidiately by adding 2 and x0 in x18
addi x19, x0, 3 # store immidiately by adding 3 and x0 in x19
add x20, x18, x19 # store value in x20 by adding values of x18 and x19
sw x20, 8(x0) # store value of x20 in x0 at address 8
Memory Output:
Output:
Explanation:
This code is storing by adding x0 and 2 in x18, by adding 3 and x0 in x19. Then it add x18 and x19
and storing it in x20. And store value of x20 in x0 at offset of 0+8.
Code:
.text
addi x18, x0, 5 # store immidiately value by adding 5 and value of x0
addi x19, x0, 3 # store immidiately value by adding 3 and value of x0
and x20, x18, x19 # performs AND operation on the values of x18 and x19 in binary
store result in x20
or x21, x18, # performs OR operation on the values of x18 and x19 in binary and
store in x21
xor x22, x18, x19 # performs XOR on values of x18 and x19 in binary store in x2
7|Page
Spring 2025 CA Lab-1
Output:
Execution Information:
Explanation:
This code initializes registers x18 and x19 with the values 5 and 3, respectively. It then
performs bitwise AND, OR, and XOR operations on these two values, storing the results in
registers x20, x21, and x22.
8|Page
Spring 2025 CA Lab-1
Task-4: Implement a simple assembly language program and show the pipelining diagram
from the processor tab.
Use Pipelined processor option for this task.
Explain the code in your words on your own understanding level.
Notice the values in the memories.
Code:
.text
addi x18,x0,2 # store immidiately by adding value of x0 (0) and 2 and in the x18
addi x19,x0,3 # store immidiately by adding value of x0 (0) and 3 and in the x19
add x20,x18,x19 # store immidiately by adding values of x18 and x19
sw x20, 0(x0) # store values of x20 in x0 by the offset of 0
sw x18, 4(x0) # store values of x18 in x0 by the offset of 4
sw x19, 8(x0) # store values of x19 in x0 by the offset of 8
Output:
Execution Information:
Memory Output:
9|Page
Spring 2025 CA Lab-1
Explanation:
This code initializes registers x18 and x19 with the values 2 and 3, respectively, and
calculates their sum, storing it in register x20. It then saves the values of x20, x18, and x19
to memory at offsets 0, 4, and 8 from the address in x0.
Conclusion:
In this lab, I have learned the basics of RISC-V assembly language using the Ripes simulator. I
practice writing and executing simple programs that describes arithmetic and data transfer
instructions. I gained a better understanding of register and memory flow of execution. Overall,
this lab helped me develop practical knowledge in assembly programming and enhance my
technical knowledge in Ripes Simulator.
10 | P a g e
Spring 2025 CA Lab-1
Domain Criteria Excellent (10) Good (8-9) Satisfactory (6-7) Improvement (4-5) Marks
Obtained
Successfully Successfully Had difficulty Did not complete tasks
Assembly completed tasks with completed tasks completing tasks and and struggled with lab
Psychomotor Programming understanding and but with some used lab equipment equipment
(P3) (CLO-1) good use of understanding with errors.
equipment. gaps
11 | P a g e