Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Logical AND implementation in x86_64 Linux assembly

I’m trying to implement logical NOT and logical AND
in assembly, I did logical NOT already using x < 1
but I can’t think of how to implement AND, I can use
binary and but that’s broken for negative numbers (it
assumes -1 is true) and it doesn’t make any sense
when NOT obviously works because -1 < 1 would return 1

So I’m confused, how could I do it, any known implementation
which I could use? I can’t find it, been looking for a while

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The standard solution is to implement a && b as

if (a)
    return (b);
else
    return (0);

i.e. use a conditional jump. On sufficiently new x86, you can also use a cmov instruction like this:

; assumes input in eax and ebx
mov ecx, eax    ; ecx = A
test ebx, ebx   ; B?
cmovnz ecx, ebx ; ecx = A ? B : A
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading