Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:04+00:00 2026-05-23T18:29:04+00:00

How can I code the C ‘&&’ operator in x86? For example: int a

  • 0

How can I code the C ‘&&’ operator in x86? For example:

int a = ...
int b = ...
int c = a && b;

What would be the equivalent of the last line in x86?

EDIT: I want to do the above without any jumps.

EDIT: g++ generates this, but I don’t understand it:

testl   %edi, %edi
setne   %dl
xorl    %eax, %eax
testl   %esi, %esi
setne   %al
andl    %edx, %eax
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:29:05+00:00Added an answer on May 23, 2026 at 6:29 pm

    Here is how GCC implements it at -O3.

        movl    8(%esp), %edx  ;; load argument into edx
        xorl    %eax, %eax     ;; eax = 0
        movl    4(%esp), %ecx  ;; load other argument into ecx
        testl   %edx, %edx     ;; Is EDX nonzero?
        setne   %al            ;; al = 1 if Z = 0
        xorl    %edx, %edx     ;; EDX = 0
        testl   %ecx, %ecx     ;; Is ECX nonzero?
        setne   %dl            ;; dc = 1 if Z = 0
        andl    %edx, %eax     ;; edx &= eax
    

    Note that this code does not short-circuit; this is because in this case GCC can prove that there are no side effects from the second argument. If the second argument has side-effects, you must implement it using jumps. For example:

    int test(int *a, int *b) {
      return (*a)++ && (*b)++;
    }
    

    becomes:

    test:
            pushl   %ebx            ;; save ebx
            movl    8(%esp), %eax   ;; load a into eax
            movl    12(%esp), %ecx  ;; load b in to ecx
            movl    (%eax), %edx    ;; *a -> edx
            leal    1(%edx), %ebx   ;; ebx = edx + 1
            movl    %ebx, (%eax)    ;; *a <- ebx
            xorl    %eax, %eax      ;; eax = 0
            testl   %edx, %edx      ;; if the old value of *a was 0...
            je      .L2             ;; jump to the end
            movl    (%ecx), %eax    ;; *a -> eax
            testl   %eax, %eax      ;; does *a = 0?
            leal    1(%eax), %edx   ;; edx = *a + 1 (does not set flags!)
            setne   %al             ;; al = 1 if Z (ie, if a = 0 at the testl above)
            movl    %edx, (%ecx)    ;; save edx to *a (increment *a)
            movzbl  %al, %eax       ;; zero-extend al to eax
    .L2:
            popl    %ebx            ;; restore ebx
            ret                     ;; return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can code be resource? I will give you an example: I want to
Is there a program or API I can code against to extract individual files
In the aspx code view , we can code like this: <asp:ListBox runat=server> <asp:ListItem
One thing I lack understanding on is how can code compiled for an Intel
I am using XAMPP and was wondering if I can code my site to
Python is pretty clean, and I can code neat apps quickly. But I notice
Surprisingly as you get good at vim, you can code even faster than standard
Can VBA code instantiate and use .NET objects? The specific class I'm interested in
Can source code examples be kept in a SQL database while retaining all formatting
Any code can be reused in a way or an other, at least if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.