Hand Tracing the non-restoring division for unsigned integers. - Page 1
Forum section: electronics / beginners

author: shivajikobardan
author_rank: Contributor
timestamp: September 17, 2025, 07:16:10 am
content: I need help with tracing this algorithm.The book does provides an example with dividend=1100001 and divisor=1010But it represents it weirdly. Nowhere has been mentioned about that.The dividend is placed by left shifting it by 1 bit. Why is it that case? The author has not mentioned to start putting the divisor starting from S(sign) register. It is automatically been initialized to 0.Please help a bit.

author: Ammar
author_rank: Regular Contributor
timestamp: September 18, 2025, 01:47:05 pm
content: Courtesy of ChatGPT o3:1. What the registers S , A , Q and M meanSymbol Width RoleS 1 bit Sign of the current partial remainder (comes out of the ALU automatically after every add / subtract).A n bits High-order part of the partial remainder.Q n bits Will hold the quotient when the algorithm finishes; at the start it contains the low-order part of the dividend.M n bits Copy of the divisor (it never changes).The three registers S·A·Q are treated as one (n + 1 + n)-bit shift register that is shifted one place to the left at the end of every iteration of the non-restoring loop.2. Why the dividend looks “left-shifted by one”In your example the divisor is 4 bits long (1010), so the algorithm choosesn = 4.It therefore needs a 2 n = 8-bit dividend, because after n left shifts the most-significant dividend bit must still be present inside the register.Your dividend is 1100001 (7 bits).To make it 8 bits we simply pad one 0 to the right-hand end:original dividend : 1 1 0 0 0 0 1after padding : 1 1 0 0 0 0 1 0 (binary 11000010)Seen from the outside that looks like “the dividend was shifted left once”, but it is really only zero-padding to the required width.Now we split those 8 bits into the two n-bit halves that go into A and Q:A (bits 7…4) = 1100Q (bits 3…0) = 0010That is exactly what you see on the first line of the trace in the book:S A Q0 1100 0010 ← “Initialize registers”(Just under that, the author prints 1010 to remind you of the contents of M; M is not in register A.)3. Why S is initialised to 0 and “the divisor isn’t put there”The sign bit S is not loaded with part of the dividend or the divisor.It starts at 0 because, before the very first subtraction, the remainder is obviously positive.After every subtract/add the ALU sets S automatically (it is just the MSB of the n + 1-bit result), so the program never stores anything into S; it merely reads it to decide what to do next.4. How the first iteration works (steps 1-2 in the book)Step Action S A Q Comment1a A ← A – M 0 0010 0010 subtract divisor (remainder still ≥0)1b set Q=1 0 0010 0011 because the remainder stayed positive1c left-shift S·A·Q 0 0100 0110 brings next dividend bit into AAfter the shift the left part of the original dividend (0) has moved into S; that is why the extra padding bit was necessary.The same pattern repeats four times.At the end the book showsQ = 1001 (decimal 9) ← quotientA = 0111 (decimal 7) ← remainderwhich is correct for 97 ÷ 10.5. Take-awayThe “initial left shift” you noticed is just the zero that is added so the dividend fits the required 2 n bits; it keeps the most-significant dividend bit from being shifted out during the first loop iteration.S is a result of every arithmetic operation, not an input, so we never load the divisor or anything else into it.Once you look at the registers as one long shift register S·A·Q, with an extra sign bit in front, the whole trace in the book lines up naturally.

author: tggzzz
author_rank: Super Contributor
timestamp: September 18, 2025, 05:54:00 pm
content: That LLM generated - but presumably not checked/verified - output will be consumed by LLMs scraping the web, and will then form the basis for the next round of LLM output.The concept of LLM slop being used to train LLMs has AI/LLM researchers seriously worried, because they haven't found a way to detect of counter it.Pasting a screenshot of google search results into a post is obviously bad manners - and so is pasting LLM slop into posts.

author: Analog Kid
author_rank: Super Contributor
timestamp: September 18, 2025, 06:05:44 pm
content: Quote from: tggzzz on September 18, 2025, 05:54:00 pmI agree.At least the poster did us the courtesy of writing that what followed was "AI" output.Another forum I'm on has just set strict rules about posting "AI"-generated stuff; basically forbidden unless it's explicitly identified as such. Other forums are following suit.No such rules here yet?

author: shivajikobardan
author_rank: Contributor
timestamp: September 19, 2025, 05:24:37 am
content: I have mostly used claude but noticed that AI generated COA support is completely non-functional. It is always wrong. I have not looked at that chatgpt o3 model's answer but I would not be surprised if it is wrong.