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.