Microprocessor Question -- ALU operations

In summary, the book says that if the number is negative, then the result should be in 2's comp form. However, the student thinks that the number is negative and so they get the wrong answer. The student tries to solve the next part but does not know how to start. The book says that if the number is positive, then the 1's comp and 2's comp is the same number and so the student replaces the -64 with -128 +64 and gets the correct answer.
  • #1
jaus tail
615
48

Homework Statement


upload_2017-12-17_17-9-15.png
[/B]

Homework Equations


Division by two means moving the bits right by 1 unit.
2's complement = 1's complement + 1

The Attempt at a Solution


For Question: 6
Number is 11010110 This is 2's complement.
So to find original number we subtract by 1 and get: 11010101
Now we do 1's complement to get original number: 00101010
Now we move right by 1 bit and get: 00010101

But book says answer is D
Where am I wrong?
 

Attachments

  • upload_2017-12-17_17-9-15.png
    upload_2017-12-17_17-9-15.png
    12.5 KB · Views: 965
Physics news on Phys.org
  • #2
If you divide a negative number by 2, the quotient is a negative number. Since 2s compliment numbers represent negative, the result should be in 2s compliment form
 
  • Like
Likes jaus tail
  • #3
jaus tail said:
For Question: 6
Number is 11010110 This is 2's complement.
So to find original number we subtract by 1 and get: 11010101 This is where I think you are wrong
Now we do 1's complement to get original number: 00101010
Now we move right by 1 bit and get: 00010101

But book says answer is D - Where am I wrong?
You know you are wrong, because you start with a negative number, divide by +2 and end up with a positive number.

I think you have wrongly reversed the trick for making numbers into 2's comp.
 
  • Like
Likes jaus tail
  • #4
jaus tail said:
For Question: 6
Number is 11010110 This is 2's complement.
Is this binary string representing a positive number or a negative number?
 
  • #5
Thanks. I took 2's complement of number, did rotate by 1 to right side of each bit and then again took 2's complement and that gave me the answer.
So 2's complement of:
110110110
first do minus 1
So I get:
110110110
- 00000001
= 11010101

Now I do 1's complement of this and get:
00101010
Now rotate by 1 bit right side and this becomes
00101010
to
00010101
Now first take 1's complement
00010101
becomes
11101010
Now take 2's complement means add +1 and this becomes
11101011
This is answer. Thanks. But this is horrible. In exam I'd get stuck somewhere. There is so much to remember.
How to solve the next part?
I don't even know how to start?
Carry Bit is 0. Does 1's complemet or 2's complement change that?

But how to solve the next question. Book answer is A. I
 
  • #6
NascentOxygen said:
Is this binary string representing a positive number or a negative number?

I think it's negative number because MSB is 1
For positive number the 1's complement and 2's complement is same number.
Like: +4 = 0100
It's 1's complement and 2's complement is 0100
I checked on google.
 
  • #7
jaus tail said:
I think it's negative number because MSB is 1
So once you've determined that number, don't forget to show its negative sign.
 
  • Like
Likes jaus tail
  • #8
jaus tail said:
... But this is horrible. In exam I'd get stuck somewhere. There is so much to remember.
Yeah, I know how you feel. If you do it a lot, it will become easy like common arithmetic. But I don't. I'm no good at maths, so I just remember how the numbers work and use column values.
So for 8 bits, MSB is worth -128 and the other 7 bits, +64,+32 ..., +1. (Then you could just do the arith in denary if you like!)

But to think of the binary; say you had -108 for eg. That would be -128 +16 +4 or 1001 0100
Now if you want that divided by 2 (to get -54) you could have that as -64 +8 +2 because that is half of all the column values.

But in 8bit 2's comp only the MSB is negative. So we replace that -64 with -128 +64 and our result is then -128 +64 +8 +2 or 1100 1010
What you've done is to simply shift the 2's comp right 1 bit, as you might expect for div by 2, but keep the MSB at 1

Any time you have a 2's comp negative number, MSB is 1 and Rshift moves it to be half the value but positive instead of negative. So long as the MSB is replaced with another 1, the total of these two becomes half the MSB value but negative.

If the 2's comp is a positive number, MSB is 0 and R shifting it means it is still 0. If we keep the MSB as 0, then nothing has changed here, but all the positive values have moved down 1 bit and are half their value as required.
2sComp.png


Once you've got your correct result, by whatever means, you can see how the bits move. Then it's easy to decide which shift operations do the job.
Remember they've mentioned the carry bit (which is often ignored), so that probably gets used here.
 

Attachments

  • 2sComp.png
    2sComp.png
    2.6 KB · Views: 339
  • Like
Likes jaus tail
  • #9
Thanks for all the replies.
 

1. What is the purpose of an ALU in a microprocessor?

The Arithmetic Logic Unit (ALU) is a crucial component of a microprocessor that performs arithmetic and logical operations on data. It is responsible for carrying out calculations, comparisons, and other mathematical functions necessary for the functioning of a computer system.

2. How does the ALU perform basic arithmetic operations?

The ALU uses binary logic to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It does this by breaking down the operations into simpler tasks, such as shifting and adding bits, and then combining the results to produce the final output.

3. What is the difference between logical and arithmetic operations in the ALU?

Logical operations in the ALU are used to compare and manipulate binary data, while arithmetic operations are used to perform mathematical calculations. Logical operations include AND, OR, and NOT, while arithmetic operations include addition, subtraction, multiplication, and division.

4. Can the ALU perform more complex operations?

Yes, the ALU can also perform more complex operations such as bitwise operations, which involve manipulating individual bits of a binary number. It can also perform shift operations, which involve moving bits to the left or right within a binary number.

5. How does the ALU handle errors or exceptions during operations?

The ALU is designed to handle errors or exceptions during operations by using flags and error codes to indicate when an error has occurred. These flags can then be used by the microprocessor to direct the flow of the program and handle the error appropriately.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top