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

  • SEARCH
  • Home
  • 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 7608105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:50:00+00:00 2026-05-31T00:50:00+00:00

I read a book about assembly, which have the next code. The code comapre

  • 0

I read a book about assembly, which have the next code. The code comapre (lexcially) two arrays (int value), and return 1 if the first is bigger, 0 if it equal or -1 otherwise:

Comprator:
  push ebp
  mov ebp, esp
  mov esi, [ebp+8] ; first - A
  mov edi, [ebp+12] ;Second - B
  mov ecx, [ebp+16]
  comp esi,edi,ecx
  jl less
  je equal
  mov eax, 1
  jmp end
equal:
   mov eax,0
   jmp end
less:
   mov eax, -1
   jmp end
end:
   pop ebp
   ret

%macro comp 3
    mov ecx, %3
%%l:
    mov eax,[%1]
    mov ebx,[%2]
    cmp eax,ebx
    jne %%done
    add %1, 4
    add %2, 4
    loop %%l
    sub eax,eax
%%done:
%endmacro

I don’t undestand why it needs the line: sub eax,eax. If we have two identical arrays, so in the last compare, we would get, for example, cmp 3,3 – then we will exit from the loop, and for the line je equal – it will return true, and would jump to end.

  • 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-31T00:50:02+00:00Added an answer on May 31, 2026 at 12:50 am

    It’s to set the Z flag so the je equal after the macro will know that the two arrays were equal. The Z flag would be set or cleared by the cmp eax, ebx, and if it’s clear at that point, control will transfer to done — unfortunately, immediately after that it does a couple of adds, which will (probably) clear the Z flag again, so the sub eax, eax is needed to set it again for the conditional jumps after the macro.

    The real question would be why you need the mov eax, 0 at equal: — and the answer is that you don’t. Along with setting the Z flag, the sub eax, eax also sets eax to 0, which can/could be returned directly. Even if you did decide to re-load the 0 value for some reason, you probably want to use the sub eax, eax (or xor eax, eax) to do so (the code is a little smaller and at least on some processors, faster as well).

    Edit: I should add that at least in my opinion, this is a fairly poor use of a macro. At the very least, there should be some comments to specify the macro’s interface, which would probably have answered the question before it was asked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read this book section about git branches. I have create a branch called
I have read my first book on c# and feel completely clueless about LINQ.
I'm new in c#. I have read some book about c# for beginners. Now
I read below line in one book about buffered input Why have buffers? First,
I have read a few tutorials and in a book about using Active Record,
I read a book about scheme, and it has the next example: (define map
I have this subtle question about virtual memory. In one book I read this
For years, maybe 10, I've been fascinated with cryptography. I read a book about
Almost every Java book I read talks about using the interface as a way
I just read about the breadth-first search algorithm in the Introduction to Algorithms book

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.