News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Register usage in PROCs

Started by CCurl, October 15, 2015, 03:00:43 AM

Previous topic - Next topic

jj2007

Quote from: CCurl on October 23, 2015, 04:10:11 PM
Thanks. Checking a reg and branching if ZERO ..


     test   eax, eax
     jz     isZero

or

     cmp   eax, 0
     je    isZero

Or is there another better way?

cmp eax, 0 is one byte longer than test eax, eax (but for al, they both have the same size).
Otherwise they are equivalent, also speed-wise.

Note that for readability of code you can use
  test eax, eax
  .If Zero?
    nop
  .elseif Sign?
    nop
  .else
    nop
  .endif


Code generated is not a single byte longer, but when sources are getting longer and longer, you will appreciate this syntax.

CCurl

Quote from: jj2007 on October 23, 2015, 06:28:28 PM

..

cmp eax, 0 is one byte longer than test eax, eax (but for al, they both have the same size).
Otherwise they are equivalent, also speed-wise.

Note that for readability of code you can use
  test eax, eax
  .If Zero?
    nop
  .elseif Sign?
    nop
  .else
    nop
  .endif


Code generated is not a single byte longer, but when sources are getting longer and longer, you will appreciate this syntax.
Good tip!  :t