News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Binary Division Question

Started by Epison07, October 06, 2005, 11:31:09 PM

Previous topic - Next topic

Epison07

I did a little google searching and couple find anyting to help me out here. It is also not in my Assembler book I have for my CS232 class. Anywayz, I have a question about "Restoring Division". We have went over it in my class, but I havent quite been able to get a grasp on it. Now I know (believe) this is an assembler forum, so I figured this would be some basic information to you guys and figured you would be able to help me out with ease. Sorry if is in the wrong forum, but I figured this would be the best one.
Anywayz, Like I was saying, I am having trouble with Restoring Division with binary numbers. We have also went over non-restoring, but first we are supposed to learn restoring. Anyway, I have tried several different times with different numbers going thro a little different and have yet to get the correct answer. So, I figured I would enter one of my attempts, which turned out very close to the answer I should have gotten. I was hoping I just made a mistake and finally figured it out, but I cant find any mistake. So, plus read thro this and either point out my mistake, or where I am completely doing it wrong. Please help :-\

11 / 2 = 5 with a remainder of 1

11: 01101
2: 00010
-2: 11110                   (I understand these are really 32 bit numbers, but assume the fifth digit is the signed number

00000 01101
shift <-
00000 1101_
+ 11110
11110 11010              (signed is now a 1, which is wrong, so you add +2 now?)
+00010
00000 11010
shift <-
00001 1010_
+ 11110
11111 10100
+00010 10100
00001 10100
shift <-
00011 0100_
+11110
00001 01001
shift <-
00010 1001_
+11110
00000 10011
shift <-
00001 0011_
+11110
11111 00110
+00010
00001 00110
1        6
So the remainder is 1 and the quotent is 6, which it should be five.
Did I mess up somewhere? I also tried adding +2 everytime,
Please help???

-Ep

dsouza123

http://arxiv.org/pdf/cs.AR/0508038

A pdf file with a clear example worked out.  The math and explaination only no code.

dsouza123

For  11 / 2

01011 = 11
101 = 2  in 2's complement   not 010 -> 101  add 001 -> 110

_01011
_110 +
---------
1000  leading 1 so OK, drop down 1 ( second from end )    use 1 for quotient so far

_0001
__110+
-----------
_0111 leading 0 so Restore,  add regular 2     use 0  ( append to quotient) -> 10

__111
__010+
----------
_1001 leading 1 so OK, drop down 1 ( at end )   use 1 ( append to quotient) -> 101

__ 0011
___110+
--------------
__1001 leading 1 so OK, done leaving remainder    ignore just verifies remainder

001 is remainder ( above with leading 1 removed)

101 is quotient ( use leading x's except last which verified the remainder)

tenkey

Quote from: Epison07 on October 06, 2005, 11:31:09 PM

11 / 2 = 5 with a remainder of 1

11: 01101
2: 00010
-2: 11110                   (I understand these are really 32 bit numbers, but assume the fifth digit is the signed number

1        6
So the remainder is 1 and the quotent is 6, which it should be five.

1101 = 13
1011 = 11
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8