赋值操作符

赋值操作符

+=和其他赋值操作符

out += in;//将out和in相加并将结果赋值给out
//out = out + in;

在这里插入图片描述

注意:这些操作符都是阻塞赋值
packdage definitions;
	typedef enum logic[2:0] {ADD,SUB,MULT,DIV,SL.SR} opcode_t;
	typedef enum logic{UNSIGNED,SIGNED}operand_type_t;
	typedef union packed{
		logic[23:0] u_data;
		logic signed[23:0] s_data;
	}data_t;
	typedef struct packed{
		opcode_t opc;
		operand_type_t op_type;
		data_t op_a;
		data_t op_b;
	}instruction_t;
endpackage

import definitions::*;//将包导入$unint域

module alu(input instruction_t instr,outpout data_t alu_out);
	always_comb
	begin
		if(instr.op_type == SIFNED)
		begin
			alu_out.s_data = instr.op_a.s_data ;
			unique case(instr.opc)
				ADD:alu_out.s_data += instr.op_b.s_data ;
				SUB:alu_out.s_data -= instr.op_b.s_data ;
				MULT:alu_out.s_data *= instr.op_b.s_data ;
				DIV:alu_out.s_data /= instr.op_b.s_data ;
				SL:alu_out.s_data <<<= 2;
				SR:alu_out.s_data >>>= 2 ;
		 	encase
		end
		else
		begin
			alu_out.s_data = instr.op_a.u_data ;
			unique case(instr.opc)
				ADD:alu_out.u_data += instr.op_b.u_data ;
				SUB:alu_out.u_data -= instr.op_b.u_data ;
				MULT:alu_out.u_data *= instr.op_b.u_data ;
				DIV:alu_out.u_data /= instr.op_b.u_data ;
				SL:alu_out.u_data <<<= 2;
				SR:alu_out.u_data >>>= 2 ;
		 encase
		end
	end
endmodule
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

傻童:CPU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值