kcmallard
kcmallard

Reputation: 197

How would I implement a 1-bit slt operation in an ALU? (MIPS)

This is a homework assignment, so I'm not looking for an answer, but guidance. The instructions say, "How would you implement a 1-bit slt operation in an ALU? Describe your solution using only AND, OR, and NOT. No need to diagram the logic gates, just clearly describe the process with all possible inputs, expected outputs, and the logical expression that represents SLT."

So far...

I'm thinking of having A and B as 32-bit inputs into the ALU. I was also thinking of taking the two's complement of B. Then, I would add A and B together. If the output is anything other than a negative, return 0. In my thinking, that sounds like I have implemented a 1-bit slt operation. But, how do I show "if result is negative return 1" using only AND, OR, and NOT?

Upvotes: 0

Views: 5966

Answers (2)

Jee Seok Yoon
Jee Seok Yoon

Reputation: 4806

Guidance: Draw a truth table for slt instruction.


Answer: Truth table for 1 bit slt ALU instruction.

A  B  Q
0  0  0  //A=B no!
0  1  1  //A<B yes!
1  0  0  //A>B no!
1  1  0  //A=B no!

Q(output) is set high only if A< B.

Therefore, Q=A'B. (or Q=~A&B in verilog)

Upvotes: 0

Jesus Ramos
Jesus Ramos

Reputation: 23268

In your case assume the high bit is the sign bit. Mask the result by AND'ing with 1 << 31 to check sign bit. If you want to return either 1 or 0 then you can use another NOT operation on the result of masking and then AND with 1 and return that.

Example:

If the result is negative you get (in bits) 1....... then NOT of this will give you 0111111..... and finally the last AND will give you 000....1 which is the result you want.

Upvotes: 1

Related Questions