user4386721
user4386721

Reputation:

How would one go about implementing an add immediate in Verilog for an ALU?

I'm working with a 32-bit ALU for a MIPS processor. I've read Pong Chu's book on verilog and other texts but I haven't really come across a concrete answer as to how exactly I would implement an add immediate with verilog?

for example with the asm code: addi Y, A, immediate

add is as simple as y = a + b but how do i interpret an immediate operand?

Upvotes: 0

Views: 1911

Answers (1)

scary_jeff
scary_jeff

Reputation: 4374

In overview, you can implement different operand capability for a function such as this in the following way:

Implement an add function where the operands are fed via a multiplexer. The multiplexer will have a few inputs, one of which will be an immediate value from your instruction word. Use the op code part of your instruction word to select which multiplexer input to use for the addition.

Other inputs to the multiplexer might be the output of a 'registers' memory, a forwarding path from somewhere else in your processor, etc.

I have not provided any code, but this would be completely dependent on what existing structure you already had. hopefully this overview will be enough to put you on the right track.

The wikipedia page on the MIPS architecture has a diagram showing multiplexers used in this way.

Upvotes: 1

Related Questions