How to zero a register? Let me count the ways:

 

  • MOV ax, 0
  • SUB ax, ax
  • XOR ax, ax

 

What, if any are the differences in the above?

 


Camron: Each instruction zeros the register in a different way which also results in different flags being set.

 

 

MOV ax, 0 puts the binary of the number 0 (which is 0) into the ax register, completely replacing the original value(if any). Does not set any flags.

SUB ax, ax uses arithimetic to subtract the value stored in the ax register by itself which will always result in 0. Sets all flags.

      11010110

   -  11010110

      00000000

 

XOR ax, ax Performs an 'exlusive or' to itself which will always result in 0. Sets the Overflow and Carry flag to 0, sets the Sign and Zero flags, and leaves  the Auxiliary flag unpredictable.

 

1011

XOR

1011

0000

 

 


Page Information

  • 3 months ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts