Assembler instructions complement neg

NEG (complement command)

  1. Instruction format: neg reg / mem
  2. Meaning: reg / mem <- 0- reg / mem, i.e. 0 Save operands, and the result obtained is stored in the specified register or a memory unit (or operands bitwise, end plus 1 )
  3. Operand is a positive number of cases
mov al,64h  
neg al	    ; al=9ch

First clear that in the computer, the data is stored in the form of a complement .

  • 64h complement representation: 01100100 (the original number of positive and negative, the same complement)
  • Bitwise: 10,011,011
  • The last one plus 1: 1001 1100 = 9ch
  1. The case where operand is negative
mov al,-8         
neg al            ; al=08h
  • -8 original code represents: . 1 000 1000
  • Anti-8 code represents: . 1 111 0111
  • -8 complement representation: . 1 111 1000
  • Bitwise: 00,000,111
  • The last one plus 1: 0000 1000 = 8 = 08h
  1. Summary
    When using neg instruction
  • First operand complement representation into
  • Then operand bitwise
  • Finally, add 1

  At this time, we are able to find the right result.


Of course, it is also from the perspective of calculation is calculated ( recommended using this method ), and is relatively simple. Still above examples illustrate

  • 当 al = 64h,neg al <=> 0 - al <=> 0 - 64h = -64h
  • 当 al = -8,neg al <=> 0 - al <=> 0 - (-8)= 8

Still want to emphasize is: the computer, the data is stored in the form of complement .

  1. Let us seek -64h complement. Negative complement code + 1 = trans, trans negative code: change the sign bit, the rest of you bitwise
  • -64h original code: . 1 110 0100
  • -64h Anti-code: 1 001 1011
  • -64h 补 码: 1001 1100 = 9ch
  1. 8 complement. The original number of positive and negative, the same complement
  • 8 original code: 0 000 1000
  • 8 anti-code: 0 000 1000
  • Complement 8: 0 000 8 1000 =

As can be seen, this method is for the operand is negative relatively simple case, the equivalent of a direct absolute value . The operand is a positive number , the seek is a positive number indicates the opposite of the complement

to sum up:

  1. Operand> 0: negative sign, code negated
  2. Operand <0: Direct absolute value
Published 50 original articles · won praise 38 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42250302/article/details/103432850