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 233149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:04:36+00:00 2026-05-11T20:04:36+00:00

I recently needed to debug a program at assembly level. I don’t have a

  • 0

I recently needed to debug a program at assembly level. I don’t have a lot of assembler experience, so I figured I’d write some simple C programs and single-step through them in order to get a feeling for the language before I’d start debugging other peoples code. However, I really don’t get what gcc made of these two lines (compiled with -ggdb -O0):

items[tail] = i;
tail = (tail+1) % MAX_SIZE;

where MAX_SIZE is #defined to be 5 and i is a local variable (stored in 0x8(%ebp), i guess). According to gdb, this becomes:

0x08048394 <queue+17>:  mov    0x8049634,%edx
0x0804839a <queue+23>:  mov    0x8(%ebp),%eax
0x0804839d <queue+26>:  mov    %eax,0x804963c(,%edx,4)
0x080483a4 <queue+33>:  mov    0x8049634,%eax
0x080483a9 <queue+38>:  lea    0x1(%eax),%ecx
0x080483ac <queue+41>:  movl   $0x66666667,-0xc(%ebp)
0x080483b3 <queue+48>:  mov    -0xc(%ebp),%eax
0x080483b6 <queue+51>:  imul   %ecx
0x080483b8 <queue+53>:  sar    %edx
0x080483ba <queue+55>:  mov    %ecx,%eax
0x080483bc <queue+57>:  sar    $0x1f,%eax
0x080483bf <queue+60>:  mov    %edx,%ebx
0x080483c1 <queue+62>:  sub    %eax,%ebx
0x080483c3 <queue+64>:  mov    %ebx,-0x8(%ebp)
0x080483c6 <queue+67>:  mov    -0x8(%ebp),%eax
0x080483c9 <queue+70>:  shl    $0x2,%eax
0x080483cc <queue+73>:  add    -0x8(%ebp),%eax
0x080483cf <queue+76>:  mov    %ecx,%edx
0x080483d1 <queue+78>:  sub    %eax,%edx
0x080483d3 <queue+80>:  mov    %edx,-0x8(%ebp)
0x080483d6 <queue+83>:  mov    -0x8(%ebp),%ebx
0x080483d9 <queue+86>:  mov    %ebx,0x804963

Since 0x804963c is the address of items, i can see how the first line of C code works. Also, 0x8049634 is the address of tail, so I guess queue+33 and queue+38 are equivalent to %ecx = tail+1…but I have no idea what is happening afterwards. Who would have thought a simple modulo could be this complicated?

  • 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-11T20:04:36+00:00Added an answer on May 11, 2026 at 8:04 pm

    It’s a way to avoid having to do a more expensive division instruction. I was also quite stumped the first time I encountered this. The fun thing is that searching for the magic numbers that are used for this trick (in this case 0x66666667) often gives results explaining this trick. (I believe at the time it was the only concrete thing I had to go on because I didn’t have the sources.)

    A quick search gave me this blog post: http://blog.dkbza.org/2007/09/reverse-engineering-compiler-produced.html It has some useful links at the bottom (including an indirect link to a paper on this trick).

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

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A makeself self-extracting executable that starts the install script using… May 12, 2026 at 6:07 pm
  • Editorial Team
    Editorial Team added an answer Since you get the string from a servlet i can… May 12, 2026 at 6:07 pm
  • Editorial Team
    Editorial Team added an answer Check if your server allows to run user instances. If… May 12, 2026 at 6:07 pm

Related Questions

I recently needed to debug a program at assembly level. I don't have a
I don't know much about creating Makefiles, but I've been reading the make manual
I recently upgraded to the iPhone 3.0 sdk. Once i did this, i needed
My current view is no, prefer Transact SQL stored procedures because they are a
I recently needed to serialize a datatable to JSON. Where I'm at we're still

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.