How does the Prop do math?
T Chap
Posts: 4,223
There is no point to this other than I often wonder how math works internally. If you add two numbers, where does that math take place and how? Same for mult, div, sub.
Comments
The addition and subtraction is done in hardware in the cog. See this Wiki article for a starting point. The cog hardware fetches two numbers from wherever the instruction specifies and holds them in effectively internal registers, then the arithmetic unit does what the Wiki article describes and delivers the result a couple of nanoseconds later so it can be written back into the cog's memory.
Mike has brought up some good info to chew over, but I will add more.
To learn how it all works start by using logic gates (make your own to learn in depth, I used diodes first, then transistors to design logic gates), then build a half adder out of said parts. It is in some fashion all microprocessor adds using gates like the ones you should make.
Hope this helps
http://iiusatech.com/murdocca/POCA/slides/
The 3rd slide deals with arithmetics.
Once again, I'll put my plug in for the book "Code" by Charles Petzold. It does a wonderful job of explaining how the insides of the beast in the machine work, why binary, why two's compliment numbers, memory addressing busses, clocks, instruction decoding, etc....really good stuff, well explained.
I have to second this advice. Take one or two '181 chips and put switches on the inputs and leds on the outputs to see how it works. This chip was used as the basis for the ALU on a lot of minicomputers.
more relevant to this thread theres a chapter where he demonstrates an adder done entirely in gates. the first few chapters are really basic but when he puts away the relays and shows how logic gates are indavidually put togather to do stuff it gets good. i thought i understood boolean logic and bit operations really well from years of c... when he builds the first 2 to 4 decoder i had to reread and trace the wires a few times, not becuase he does a bad job but becuase i just couldnt think like a hardware guy using gates till it was layed out in front of me. his explanations are simple and easy to understand the book is insightfull, now i understand how woz designed a bunch of computers on paper before he could ever get real hardware.
im not even done with this book, have alot of other reading to do too so i give code a chapter or two a night. Anyways this is how this book helped me the other day.
so im building a little board for a 4 digit 7 segment display (like a clock). Im like u learning the prop and i thought this would be a nice simple place to start writing a driver. I start writing the driver and realise i want to add code to change the brightness, this leads me to build a board around the display usining pnp transistors to amplify the current to the 7seg without drawing more current than your suppose to from the prop. i tried with a regular npn first but it didnt boost the current enough so pnp it was.
now heres were petzolds book creeps into my head and now into my project. the pnp transistor only comes on when the base is sent a low signal or 0v from the props data pin. Well thats all fine but the driver was written to drive the display directly and was originall outputting a hi or 3.3v to turn each digit on. Basically now my driver is sending a hi but the pnp transistor will only flip for a low. so i had a few choices i could change my spin to set outa to 0, but i didnt wanna do this becuase i wanted the driver to work with a direct connection and the amplifying board. next idea is to add a flag the user can set to invert the outputs of the amplified pins. this is reasonable but adds size to the code and we only have so much room, plus i want to use this driver as the basis for a tutorial for guys like us. then i think to code and im like well why dont i just invert my signal with a hardware inverter or another transistor in this case..
soo ya i basically had to use a transistor that would invert my signal to amplify the display as bright as i wanted, and all i did was use a npn to invert the signal to the pnp but if i hadnt read code i probably wouldnt have thought about making a hardware not gate basically. its a good book lol. if i ever have to use gates to multiplex or transistors to add a byte ill know where to start and what to do becuase of code
If the adder is just a simple set of gates, the I assume there is only two registers available to add two numbers. if x + y + z is to be added, I assume this means it first adds the first two numbers into a result, then loads the result back to one of the registers then sums the last number. This would take extra time right to add 3 numbers?
Note that there are two other adders per cog, each associated with the PHSx and FRQx registers of a cog counter. These are simple adders since all they do is add the contents of FRQx to PHSx which gets clocked back into PHSx either on the next system clock or some other clock depending on the counter control register contents.