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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:55:59+00:00 2026-05-22T00:55:59+00:00

EDIT: What time complexity has algorithm implemented in this assembly ? .file a.c .section

  • 0

EDIT:
What time complexity has algorithm implemented in this assembly ?

    .file   "a.c"
    .section    .rodata
.LC0:
    .string "%d\n"
.LC1:
    .string "%d"
    .text
.globl main
    .type   main, @function
main:
    pushl   %ebp
    movl    %esp, %ebp
    andl    $-16, %esp
    subl    $32, %esp
    cmpl    $1, 8(%ebp)
    jg  .L2
    movl    $.LC0, %eax
    movl    $-1, 4(%esp)
    movl    %eax, (%esp)
    call    printf
    jmp .L8
.L2:
    movl    $.LC1, %edx
    movl    12(%ebp), %eax
    addl    $4, %eax
    movl    (%eax), %eax
    leal    24(%esp), %ecx
    movl    %ecx, 8(%esp)
    movl    %edx, 4(%esp)
    movl    %eax, (%esp)
    call    __isoc99_sscanf
    testl   %eax, %eax
    jne .L4
    movl    $.LC0, %eax
    movl    $-2, 4(%esp)
    movl    %eax, (%esp)
    call    printf
    jmp .L8
.L4:
    movl    24(%esp), %eax
    testl   %eax, %eax
    jns .L5
    movl    $.LC0, %eax
    movl    $-3, 4(%esp)
    movl    %eax, (%esp)
    call    printf
    jmp .L8
.L5:
    movl    $0, 28(%esp)
    jmp .L6
.L7:
    addl    $1, 28(%esp)
.L6:
    movl    24(%esp), %eax
    cmpl    %eax, 28(%esp)
    jl  .L7
    movl    $.LC0, %eax
    movl    28(%esp), %edx
    movl    %edx, 4(%esp)
    movl    %eax, (%esp)
    call    printf
.L8:
    leave
    ret
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3"
    .section    .note.GNU-stack,"",@progbits

Thanks!

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

    There is only a small section of your assembly where control flows in a way other than straight-ahead execution or forward jumps (or calls to printf or sscanf with a format string of "%d"). Since those sections of the code are only executed once, they have complexity O(1).

    So the only interesting complexity is in the place where a backwards jump is possible:

    .L5: movl    $0,    28(%esp)
         jmp     .L6
    .L7: addl    $1,    28(%esp)
    .L6: movl 24(%esp),    %eax
         cmpl    %eax,  28(%esp)
         jl      .L7
    

    This is just a basic for loop; in C it would look like this:

    for (int i=0; i<n; ++i);
    

    An aside: this brings up a danger of using “abstract pseudocode” to talk about the complexity of assembly; this loop does nothing so the abstract pseudocode equivalent, in some sense, is empty and has complexity O(1). The actual code, however, has complexity O(n).

    So this loop takes O(n) time, where n is the value of the input to the program as an integer. Since the rest of the program takes O(1) time, the program as a whole runs in O(n).

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

Sidebar

Related Questions

I don't edit CSS very often, and almost every time I need to go
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
What's the best (halting) algorithm for determining if a linked list has a cycle
According to the wikipedia entry on Rabin-Karp string matching algorithm, it can be used
Edit 2: For a practical demonstration of why this remains important, look no further
This book was written in the era of time sharing systems, procedural programming, and

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.