Proper way to subtract two 64 bit numbers in x86 assembly -


i'm using 32 bit system , have 64 bit number saved in edx:eax. i'm trying subtract number saved in esi:edi correct? i'm pretty sure not because after 3 iterations results incorrect.

sub %esi, %edx          #subtract 2 64 bit numbers sub %edi, %eax 

you need make 2 changes:

  1. subtract low order 32-bits first, not high order
  2. if subtraction of low order 32-bits generated borrow need subtract 1 more high order bits. fortunately cpu remembers if there borrow (in carry flag cf) , there instruction subtract borrow, sbb

here's final code

sub %edi, %eax          # subtract low order 32-bits, borrow reflected in cf sbb %esi, %edx          # subtract high order 32-bits, , borrow if there 1 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -