module sine_func( 
	input clk,rst_n,
	input[9:0] x, //input has a 10-bit resolution(from 0 to 2pi)
	output[7:0] y //output has 8-bit resolution(from -1 to 1)
    );
	 
	reg[7:0] y_q=0,y_d;
	reg[7:0] x_addr; //determines the address to be inserted in ROM
	wire[6:0] dout;
	
	always  @(posedge clk,negedge rst_n) begin
		if(!rst_n) y_q<=0;
		else y_q<=y_d;
	end
	
	//logic to obtain values of other quadrants
	always @* begin
		y_d=dout;
		case(x[9:8])
			2'b00: begin	
						x_addr=x[7:0]; //first quadrant(0 to pi/2) 
						y_d=dout+2**7; // middle point of sine wave is at 2^7
					end
			2'b01: begin
						x_addr=255-x[7:0]; //second quadrant(pi/2 to pi)
						y_d=dout+2**7;
					 end
			2'b10: begin  //third quadrant(pi to 3pi/2)
						x_addr=x[7:0];
						y_d=2**7-dout; //negative sign
					 end
			2'b11: begin  //fourth quadrant(3pi/2 to 2pi)
						x_addr=255-x[7:0];
						y_d=2**7-dout; //negative sign
					 end
		endcase

	end
	
	assign y=y_q;

	 rom_syn m0
	(
		.clk(clk),
		.addr(x_addr),  
		.dout(dout)
	);


endmodule