ALU Struggle

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ALU Struggle

bwspot
Hello,
I am new to the project and just started few weeks ago.
So far I really enjoy it and i have learned a lot already.

I was able to go through all assignments until i got to ALU.  When I look at the table I see times where both zx and nx are 1 or zy and ny are both 1

For example, lets say input x is 1 and
zx and nx are 1
therefore if zx = 1 then x = 0 and if nx = 1 then x = !x

how x can be 0 and not !x at the same time?

my though process is to manipulate the input first based on nx zx ny zy bits and then do f an no bits.

thx


Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

cadet1620
Administrator
bwspot wrote
...
For example, lets say input x is 1 and
zx and nx are 1
therefore if zx = 1 then x = 0 and if nx = 1 then x = !x

how x can be 0 and not !x at the same time?

my though process is to manipulate the input first based on nx zx ny zy bits and then do f an no bits.
Mostly correct. It's not the case that x is both 0 and !x; rather, it is x=0 THEN x=!x.

This is explained in the text in chapter 2:
For example, let us consider the twelfth row of figure 2.6, where the ALU is instructed to compute the function x-1. The zx and nx bits are 0, so the x input is neither zeroed nor negated. The zy and ny bits are 1, so the y input is first zeroed, and then negated bit-wise. Bit-wise negation of zero, (000 . . . 00), gives (111 . . . 11), the 2’s complement code of -1. Thus the ALU inputs end up being x and -1. Since the f-bit is 1, the selected operation is arithmetic addition, causing the ALU to calculate x+(-1). Finally, since the no bit is 0, the output is not negated but rather left as is. To conclude, the ALU ends up computing x-1, which was our goal.
--Mark
Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

bwspot
cadet1620 wrote
bwspot wrote
...
For example, lets say input x is 1 and
zx and nx are 1
therefore if zx = 1 then x = 0 and if nx = 1 then x = !x

how x can be 0 and not !x at the same time?

my though process is to manipulate the input first based on nx zx ny zy bits and then do f an no bits.
Mostly correct. It's not the case that x is both 0 and !x; rather, it is x=0 THEN x=!x.

This is explained in the text in chapter 2:
For example, let us consider the twelfth row of figure 2.6, where the ALU is instructed to compute the function x-1. The zx and nx bits are 0, so the x input is neither zeroed nor negated. The zy and ny bits are 1, so the y input is first zeroed, and then negated bit-wise. Bit-wise negation of zero, (000 . . . 00), gives (111 . . . 11), the 2’s complement code of -1. Thus the ALU inputs end up being x and -1. Since the f-bit is 1, the selected operation is arithmetic addition, causing the ALU to calculate x+(-1). Finally, since the no bit is 0, the output is not negated but rather left as is. To conclude, the ALU ends up computing x-1, which was our goal.
--Mark
thx for clarification,  somehow i missed that and created nonsense logic.
Now i just need to keep staring at the table until i get it.
My idea is to first make decisions based on zx , nx, zy, ny bits followed f an no.
Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

cadet1620
Administrator
This worksheet by ybakos may be helpful.

Also, this test I wrote that only tests the computation part of the ALU so that you don't need to worry about the status outputs until after you get the computation part working.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

bwspot
This post was updated on .
cadet1620 wrote
This worksheet by ybakos may be helpful.

Also, this test I wrote that only tests the computation part of the ALU so that you don't need to worry about the status outputs until after you get the computation part working.

--Mark
So i looked at the worksheet and i am not sure what should i see there.  It proves that simple operations can yield the results, but it does not help me with starting implementing the ALU.  I must be blind but I don't see it yet.  My though process is just to do what the table shows or the worksheet.
Based on the input bits zero or not zero x,y ,  negate or not negate x,y , then or or and x,y , then not out or leave it alone.  I feel like i need to use dmux to start with above,  but still cannot see the whole picture.

Edit:I am trying to start making the table work piece by piece with the smallest elements i can and then i will try to combine it.  I start seeing that i might not need any dmuxes but simple or and and.
Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

cadet1620
Administrator
bwspot wrote
My though process is just to do what the table shows or the worksheet.
Based on the input bits zero or not zero x,y ,  negate or not negate x,y , then or or and x,y , then not out or leave it alone.  I feel like i need to use dmux to start with above,  but still cannot see the whole picture.
 * The ALU.  Computes a pre-defined set of functions out = f(x,y)
 * where x and y are two 16-bit inputs. The function f is selected
 * by a set of 6 control bits denoted zx, nx, zy, ny, f, no.
 * The ALU operation can be described using the following pseudocode:
 *     if zx=1 set x = 0       // 16-bit zero constant
 *     if nx=1 set x = !x      // Bit-wise negation
 *     if zy=1 set y = 0       // 16-bit zero constant
 *     if ny=1 set y = !y      // Bit-wise negation
 *     if f=1  set out = x + y // Integer 2's complement addition
 *     else    set out = x & y // Bit-wise And
 *     if no=1 set out = !out  // Bit-wise negation

You are thinking correctly. You need to do what the the pseudo-code in the ALU.hdl comments shows, in that order. Note that in hardware you cannot replace the value of a "variable" since it is a physical wire so the pseudo-code should really look more like
    if zx=1 then x1=0 else x1=x
    if nz=1 then x2=!x1 else x2=x1
    ...
Each if-then-else is a choice between two 16-bit values. You mada a part in project 1 that does that...

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: ALU Struggle

bwspot
Finally, got my alu working.  Time to dive into another chapter.
Thx all for all the help.