Author Topic: Smallest code/cpu consuming function to get 1 of 2 values  (Read 7177 times)

Offline mik3ca

  • Jr. Member
  • *
  • Posts: 30
Smallest code/cpu consuming function to get 1 of 2 values
« 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?

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: Smallest code/cpu consuming function to get 1 of 2 values
« Reply #1 on: January 30, 2021, 11:52:57 AM »
Code: [Select]
test  ax,ax
setnz al  ; 386+ instruction.
xor   ah,ah
« Last Edit: January 30, 2021, 12:03:01 PM by fredericopissarra »