Post by Ramie Massri ChaaraniI'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