# LAB 9
## NAME - AMAN ANAND
## ROLL NO - CS22B054
## QUESTION NO 1
```javascript=
module alu_with_four_operation(a,b,sel,c);
parameter n = 4;
wire [n-1:0] x1,x2,x3,x4;
input [n-1:0] a;
input [n-1:0] b;
input [1:0] sel;
output [n-1:0] c;
assign x1 = a+b;
assign x2 = a-b;
assign x3 = a&&b;
assign x4 = a||b;
multiplexer safygsf (x1,x2,x3,x4,sel,c);
endmodule
module multiplexer(x1,x2,x3,x4,sel,c);
parameter n=4;
input [n-1:0] x1,x2,x3,x4;
input [1:0] sel;
output [n-1:0] c;
assign c = !sel[0]&!sel[1] ? x1 : sel[0]&!sel[1] ? x2 : !sel[0]&sel[1] ? x3: x4;
endmodule
```
testbench
```javascript=
module testBench_of_alu();
reg [3:0]a,b;
reg [1:0] sel;
wire [3:0]c;
alu_with_four_operation fhuba (a,b,sel,c);
initial
begin
$display("here are few test cases ");
$monitor("a=%b,b=%b,sel=%b,c=%b",a,b,sel,c);
a=4'b0111; b=4'b0110;sel='b00;
// #100 a=4'b0100;b=4'b0100;sel='b10;
#100 a=4'b0010;b=4'b0100;sel='b01;
#100 a=4'b0100;b=4'b0010;sel='b11;
end
endmodule
```
## QUESTION 2
code of module processor
```javascript=
module pro (input [7:0] ins,output reg [7:0] out);
reg [7:0] mem [255:0];
reg [7:0] register[15:0];
reg sd;
initial
begin
mem[4]=8'b00000011;
register[1] =8'b00000010;
end
assign sd= ins[7];
reg [1:0] ds;
reg [1:0] sr;
reg [2:0] off;
reg [7:0] loc;
always @(*) begin
case(sd)
1'b0: begin
ds= ins[6:5];
off= ins[4:2];
sr=ins[1:0];
loc= sr+ off;
register[ds]= mem[loc];
assign out = mem[loc];
end
1'b1: begin
ds= ins[6:5];
off= ins[4:2];
sr=ins[1:0];
loc= sr+ off;
mem[loc]= register[ds];
assign out = mem[loc];
end
endcase
end
endmodule
```
code of test bench
```javascript=
module tb ;
reg [7:0] ins;
wire [7:0] out;
pro sjfn(ins,out);
initial begin
$display("aman ka code ");
$monitor("out, %b", out);
ins = 8'b01101101; #5//output is 00000011
ins= 8'b10110011; #5 //output is 00000010
$finish;
end
endmodule
```
## QUESTION 3
### inscount0.log

code
```javascript=
#include<stdio.h>
int main(){
printf("Hello World!!");
}
```
output
