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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:34:28+00:00 2026-06-08T09:34:28+00:00

Consider a simple loop in : for(int i=0;i<32;i++) a[i] = i; The LLVM disassembler

  • 0

Consider a simple loop in :

for(int i=0;i<32;i++) 
    a[i] = i;

The LLVM disassembler shows the following assembly:

.LBB0_1:                                # =>This Inner Loop Header: Depth=1
movl    %eax, (%esp,%eax,4)
addl    $1, %eax
adcl    $0, %ecx
cmpl    $32, %eax
jne .LBB0_1
# BB#2:
xorl    %eax, %eax
addl    $140, %esp
ret

Question 1: Can anyone explain movl %eax, (%esp,%eax,4) instruction?

Moreover, Visual Studio disassembler outputs the following assembly:

    ;for(int i=0;i<32;i++)
00F290B5  mov         dword ptr [ebp-94h],0  
00F290BF  jmp         main+60h (0F290D0h)  
00F290C1  mov         eax,dword ptr [ebp-94h]  
00F290C7  add         eax,1  
00F290CA  mov         dword ptr [ebp-94h],eax  
00F290D0  cmp         dword ptr [ebp-94h],20h  
00F290D7  jge         main+7Eh (0F290EEh)  
        ;a[i] = i;
00F290D9  mov         eax,dword ptr [ebp-94h]  
00F290DF  mov         ecx,dword ptr [ebp-94h]  
00F290E5  mov         dword ptr a[eax*4],ecx  
00F290EC  jmp         main+51h (0F290C1h)  
    ;return 0;
00F290EE  xor         eax,eax   

Obvoiusly the LLVM’s output is more optimized.

Question 2: Is there an option in Visual Studio to optimize the code like LLVM does?

Update:

Results after setting Solution Configurations to Release & Optimization to Full Optimization(/Ox):

;   int a[32] = {0};
;   for(int i=0;i<32;i++)
 0039128B  xor         eax,eax  
 0039128D  lea         ecx,[a]  
 00391293  movd        xmm0,eax  
 00391297  pshufd      xmm0,xmm0,0  
 0039129C  paddd       xmm0,xmm1  
 003912A0  add         eax,4  
;   {
;       a[i] = i;
 003912A3  movdqu      xmmword ptr [ecx],xmm0  
 003912A7  lea         ecx,[ecx+10h]  
 003912AA  cmp         eax,20h  
 003912AD  jl          main+23h (0391293h)  
;   }
;   return 0;
; };
 003912AF  mov         ecx,dword ptr [ebp-4]  
 003912B2  xor         ecx,ebp  
 003912B4  xor         eax,eax  
 003912B6  call        __security_check_cookie (03916FDh)  
 003912BB  mov         esp,ebp  
 003912BD  pop         ebp  
 003912BE  ret  
  • 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-06-08T09:34:30+00:00Added an answer on June 8, 2026 at 9:34 am

    movl %eax, (%esp,%eax,4) is just an indirect memory store.

    It stores %eax into the memory location: %esp + %eax * 4. In this case:

    • %esp is the array a.
    • %eax is the index i.
    • 4 is the size of int.

    For your second question, the code output by Visual Studio looks like it was done without optimizations. There’s a lot of excessive memory loads and stores.

    For example: dword ptr [ebp-94h] appears to be the index i variable. But without optimizations, it never got promoted to a register.

    Enable optimizations, and you will see that it will produce much more sane code.

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

Sidebar

Related Questions

Consider the following sample program in which a loop is running; int main() {
Consider a simple each loop to inspect checked checkboxes: $(':checkbox').filter(':checked').each(function(){ var name = $(this).val();
Consider the following simple function void foo_rt(int n) { for(int i=0; i<n; ++i) {
Consider this simple model: A base Location table: +-------------------------------+ | Locations | +-------------------------------+ |(PK)
consider this simple function def foo(l=[]): if not l: print List is empty else
Consider this simple example - public class Person { private String name; private Date
Consider this simple AS3 class. package { import flash.display.Sprite; import flash.display.MovieClip; public class MySprite
Consider this simple XML document. The serialized XML shown here is the result of
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays

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.