NEG in Assembly

neg 3BH 

As I understand, I should get C5, but from my own calculations I got C4 (I switch each 1 to 0 and each 0 to 1). What's the problem?

3

4 Answers

neg computes the two's complement negative value, not the bitwise negative. You'll want a not instruction, or manually add one to the answer to get your desired result.

4

As you tell the story, it seems that the neg instruction (on whatever CPU you're using) effectively performs an xor of 3BH with FFH to give C4H. To that C4H result, which is the ones complement of 3BH, add 1 to get the twos complement. That will yield the correct C5H value you want. For an overview of ones and twos complement, have a look at this pretty-good Wikipedia article.

2

neg is the same as subtracting 0-the number,do it and you will get the negation of the number :0-3BH:

0-00111011:

00000000

11000100 + 1 +


11000101=C5

NEG 3Bh is equivalent to finding 2's complement.
1st, find 1's complement, a faster approach is to subtract from 15 (F in hex).

 15 - 3 = 12 ->C (12 = C in hex) 15 - 0Bh = 4h OR 15 - 11 = 4h then, add 1 to the result. C4 + 1 = C5h. 

This how you will get C5h as the result of NEG 3Bh.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like