Is it a bad practice to use the flag case as a boolean return value?

I am writing some procedures in x86 assembler that modify ZF as a means to return booleans, so I can do something like this:

call is_value_correct
jz not_correct

I am wondering if this is considered bad practice, as some coding standards suggest that simple values ​​should be returned in the AX register.

+4
source share
1 answer

Yes, do this if your code is faster and / or smaller .

asm , . "" , .

, , , . , , .

# inputs:   foo in EAX (zero-extended into RAX), bar in EDI
# pre-requisites: DF=0
# clobbers: RCX, RDX, AL (but not the rest of EAX)
# returns:  AL = something,  ZF = something else
my_func:
   ...
   setc al
   ...
   something that sets ZF
   ret

, , , asm 2018 , asm , - . ( asm, , .)

, asm / , , , .


: x86-64 OS X CF / , rax. Linux, RAX -4095 -1, x86-64 System V ABI/call.

DOS int 0x21 PC BIOS int 0x10 . , ( cmp) .

+7

Source: https://habr.com/ru/post/1692530/


All Articles