Discussion:
ALU: zero?
(too old to reply)
Ramie Massri Chaarani
2009-10-14 21:48:48 UTC
Permalink
I'm wondering if anyone could explain on page 8 chapter 4, how the
"Zero" value coming from the ALU works? I'm curious about how this works
with the signal "Branch", because, even if "Branch" is set to 1, the
zero from the ALU will always be 0 and thus the AND gate will always be
false.

Thanks

Ramie
Stephen Mann
2009-10-14 23:31:21 UTC
Permalink
Post by Ramie Massri Chaarani
I'm wondering if anyone could explain on page 8 chapter 4, how the
"Zero" value coming from the ALU works? I'm curious about how this works
with the signal "Branch", because, even if "Branch" is set to 1, the
zero from the ALU will always be 0 and thus the AND gate will always be
false.
The Zero output of the ALU is not always 0; instead, it will be high (1)
when the result of the operation in the ALU results in a 0 result.
Eg, the command sub $t1, $t1, $t1 will be 0, and the Zero output of
the ALU will be 1. This, of course, is not a particular useful
example (since we *know* that the Zero output will high); instead,
we normally use Zero to compare the value in two different registers.

In particular, the Branch signal will be high when the assembly
language instruction is beq. The beq instruction compares the values
in two registers, and if the values are equal, it branches to an offset
specified in the beq command. If the values are not equal, then
PC <- PC+4. For example, for beq $t1, $t2, 100 $t1 and $t2 are
inputs to the ALU and the ALU operation is 'sub'. If the values in $t1
and $t2 are equal, then the Zero output of the ALU will be high. And
for beq, the Branch signal is also set high (regardless of the values
in $t1 and $t2).

The result is that if $t1==$t2, then Zero=1 and Branch=1 (this last
is true since we're executing a beq command) and the program
branches. If $t1!=$t2, then Zero=0 and Branch=1, and the program
won't branch (since Zero AND Branch = 0).

Steve
a***@gmail.com
2015-03-11 23:45:20 UTC
Permalink
This explanation was amazing. A very belated thank you for posting. :)
v***@gmail.com
2015-04-29 19:23:26 UTC
Permalink
Post by Stephen Mann
Post by Ramie Massri Chaarani
I'm wondering if anyone could explain on page 8 chapter 4, how the
"Zero" value coming from the ALU works? I'm curious about how this works
with the signal "Branch", because, even if "Branch" is set to 1, the
zero from the ALU will always be 0 and thus the AND gate will always be
false.
The Zero output of the ALU is not always 0; instead, it will be high (1)
when the result of the operation in the ALU results in a 0 result.
Eg, the command sub $t1, $t1, $t1 will be 0, and the Zero output of
the ALU will be 1. This, of course, is not a particular useful
example (since we *know* that the Zero output will high); instead,
we normally use Zero to compare the value in two different registers.
In particular, the Branch signal will be high when the assembly
language instruction is beq. The beq instruction compares the values
in two registers, and if the values are equal, it branches to an offset
specified in the beq command. If the values are not equal, then
PC <- PC+4. For example, for beq $t1, $t2, 100 $t1 and $t2 are
inputs to the ALU and the ALU operation is 'sub'. If the values in $t1
and $t2 are equal, then the Zero output of the ALU will be high. And
for beq, the Branch signal is also set high (regardless of the values
in $t1 and $t2).
The result is that if $t1==$t2, then Zero=1 and Branch=1 (this last
is true since we're executing a beq command) and the program
branches. If $t1!=$t2, then Zero=0 and Branch=1, and the program
won't branch (since Zero AND Branch = 0).
Steve
Thanks a lot for your explanation, it was exactly what i've looked for!
d***@gmail.com
2017-05-08 09:45:48 UTC
Permalink
Can you please explain about bne.
I also like to know about the content of ALUOp and output of ALU Control.

Thanks,

Dipu

p***@gmail.com
2015-12-05 17:30:00 UTC
Permalink
Thank you for the answer, it is perfectly clear :)
f***@hotmail.com
2016-03-30 01:40:03 UTC
Permalink
Perfect explanation man, thank you.
Loading...