Most Efficient way to set Register to 1 or (-1)

Posted by Bob on Stack Overflow See other posts from Stack Overflow or by Bob
Published on 2010-05-13T12:53:36Z Indexed on 2010/05/13 13:04 UTC
Read the original article Hit count: 244

Filed under:
|
|

I am taking an assembly course now, and the guy who checks our home assignments is a very pedantic old-school optimization freak. For example he deducts 10% if he sees:

mov ax, 0

instead of:

xor ax,ax

even if it's only used once.

I am not a complete beginner in assembly programing but I'm not an optimization expert, so I need your help in something (might be a very stupid question but I'll ask anyway): if I need to set a register value to 1 or (-1) is it better to use:

mov ax, 1

or do something like:

xor ax,ax
inc ax

I really need a good grade, so I'm trying to get it as optimized as possible. ( I need to optimize both time and code size)

© Stack Overflow or respective owner

Related posts about registers

Related posts about assembly