NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: mik3ca on January 30, 2021, 06:22:32 AM

Title: Smallest code/cpu consuming function to get 1 of 2 values
Post by: mik3ca on January 30, 2021, 06:22:32 AM
I have an input to my program (Let's call it AX here) which can be loaded with any value, but the program only works with two values from AX. 0 and 1. So if the input is anything but a zero, then a 1 is returned. This is the code I have so far:

Code: [Select]
cmp AX,0h
  je nzero
    mov AX,1h
  nzero:

Well, I don't have to exactly have '1' as the other value, but in the end I want AX to be one of two values, at least one of them being zero.

Is there a way to crunch my code down without having to do a comparison followed by potential jump?
Title: Re: Smallest code/cpu consuming function to get 1 of 2 values
Post by: fredericopissarra on January 30, 2021, 11:52:57 AM
Code: [Select]
test  ax,ax
setnz al  ; 386+ instruction.
xor   ah,ah