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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:38:02+00:00 2026-06-02T08:38:02+00:00

I don’t have deep knowledge of assembly programming . I am trying to translate

  • 0

I don’t have deep knowledge of assembly programming.

I am trying to translate the following code from Pure C to Assembly language.

Pure-C

int i,j,temp;
for ( i = 0 ; i < 10 ; i++ )
{
    temp = global_array[i];
    for ( j = i-1 ; j >= 0 ; j-- )
    {
        if ( global_array[j] <= temp ) break; //if first value is bigger than the second value
            global_array[j+1] = global_array[j];
    }
    global_array[j+1]=temp;
}

Please, check how well did I translate from Pure C to Assembly language?

ASM

.globl _Sort
//.type AtoI,@function

//Declaration of variables
.comm _global_array,40 //this is an array of integers
.comm _temp,4 //this is the variable temp
.comm _i,4 //used for loop
.comm _j,4 //used for loop



_Sort:
/*prolog*/
pushl %ebp
pushl %ebx
movl %esp, %ebp //move the special ptr to base ptr
subl $8, %esp //allocate space for the variables local_var and temp_var

pushl %esi //index register
pushl %edi //index register


/*put code here*/
//for ( i = 0 ; i < 10 ; i++ )
//first for loop
movl $0, _i //index i = 0

ForOne:
movl _i, %eax
movl _i, %esi //move i into index register
cmp $10, %eax //if i is less than or equal 9, continue this loop
jge return
movl _global_array, %ebx
movl (%ebx,%esi,4), _%ecx
movl %ecx, _temp //temp = global_array[i]
movl _i, %eax //i-1
subl $1, %eax
movl %eax, _j //move j into index register
jmp ForTwo //jump to second for loop

ForTwo:
movl _j, %eax
cmp $0, %eax //j >= 0
jl ForOneFn //get out of 2nd loop to end of 1st loop
movl _global_array, %ebx
cmp _temp, (%ebx,%edi,4) //if ( global_array[j] <= temp ) break;
jle ForOneFn //jump to end of first loop after break
movl (%ebx,%edi,4),%ecx
addl $1,%eax //j+1
movl _j, %edi //move j into index register 
movl _global_array, %ebx
movl %ecx, (%ebx,%edi,4) //global_array[j+1] = global_array[j];

//last line of code is jump to reloop/finish 2nd loop
jmp ForTwoFn

ForTwoFn:
subl $1, _j
jmp ForTwo

ForOneFn:
addl $1, _i
jmp ForOne


return:
/*epilog*/
movl %ebp,%esp
popl %ebx
popl %ebp
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-02T08:38:04+00:00Added an answer on June 2, 2026 at 8:38 am

    First advice: use registers more intensively.

    You have 2 index variables, temporary variable and global_array address, so you have enough registers.

    Code should compile if line:

    cmp _temp, (%ebx,%edi,4) //if ( global_array[j] <= temp ) break;
    

    will be replaced by:

    cmp eax, (%ebx,%edi,4) //if ( global_array[j] <= temp ) break;, where eax is yours temp
    

    If you code this routine using registers only it will be smaller and easier to understand and debug.

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

Sidebar

Related Questions

Don't they both have to convert to machine code at some point to execute
Don't think there's much to say, here's my code for (int i = 0;
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
don't know better title for this, but here's my code. I have class user
Don't ask me how--I haven't the slightest. The following code crashes my terminal and
Don't be scared of the extensive code. The problem is general. I just provided
Don't ask me why but I need to do the following: string ClassName =
I don't know whether this is really possible, but I'm trying my best. If
Don't know how to explain it better but i'm trying to get a response
Don't be frightened, its a very basic code. Just wanted to check with you

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.