---
# System prepended metadata

title: Lab 9

---

# Lab 9
Name: Manan Chavda
Roll No.: CS22B017

---
## Question 1
```c=
module Alu(input a,input b,output reg c);
assign a = 1'b1;
assign b = 1'b0;
wire x1,x2,x3,x4;
wire [1:0] s1;
assign s1 = 2'b11;//Assign your input as select lines for the 4:1 multiplexer
initial
begin
if(s1 == 2'b00)
assign c = a+b;
else if(s1 == 2'b01)
assign c = a-b;
else if(s1 == 2'b10)
assign c = a&b;
else
assign c = a|b;
end

initial
begin
$display(c);//change select lines and input,and display your desired output
$finish;
end
endmodule
```
___
## Question 2
```c=
module processor(input [7:0] instr);
    
    reg [7:0] memory [255:0]; // 256 bytes of memory
    reg [7:0] regis [15:0]; // 16 general 8-bit registers
    
    wire op;     // Operation
    wire [1:0] des;  // Destination register
    wire [2:0] offset; // Offset
    wire [1:0] r1;  // Address register
    
    assign op = instr[7];
    assign des  = instr[6:5];
    assign offset = instr[4:2];
    assign r1  = instr[1:0];
    
    always @(*) begin
        if (op == 1'b0) // lw operation
        begin 
            regis[des] = memory[regis[r1] + offset];
        end
        else if (op == 1'b1) // sw operation
        begin 
            memory[regis[r1] + offset] = regis[des];
        end
    end
    
endmodule
```
___
## Question 3
```c=
#include <iostream>

int main(){
    int l = 1;
    for(int i=1; i<100; i++)
    {
        l *= i;
    }
    return 0;
}
```
Command executed : 
    ../../../pin -t obj-intel64/inscount0.so -o inscount0.log -- /home/system/Desktop/a.out
    

Output:    
Count 116662
___