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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:28:25+00:00 2026-05-22T03:28:25+00:00

The following is a homework problem for an assembly language class. We’re to create

  • 0

The following is a homework problem for an assembly language class. We’re to create Y86 code by reading X86 code generated from C in gdb. The purpose of the function is to sum the elements of a linked list.

As the function currently stands, it works! The correct value is contained in the %eax register when the program terminates. Unfortunately, it is only correct due to a hack. I added a halt instruction right at the end of the function, right before the ret instruction. If I uncomment that, what appears to happen is that when it carries out the ret instruction, the PC is set to 0x0. In other words, it seems to start over at the beginning, when what it should do is return to the point where it was called. It enters an infinite loop.

The code follows. It is standalone, if you have the Y86 simulator installed.

.pos    0
init:    irmovl Stack, %esp  
irmovl    Stack, %ebp  
jmp     Main  

Main:  
    irmovl  ele1, %eax  
    pushl   %eax  
    call    sum_list  
    halt  

sum_list:  
    pushl   %ebp  
    rrmovl  %esp, %ebp  
    irmovl  $16, %edx  
    subl    %edx, %esp  
    irmovl  $0, %edx  
    rmmovl  %edx, -4(%ebp)  
    jmp     L2  

L3:
    mrmovl  8(%ebp), %eax
    mrmovl  (%eax), %eax
    mrmovl  -4(%ebp), %edx
    addl    %eax, %edx
    rmmovl  %edx, -4(%ebp)
    mrmovl  8(%ebp), %eax
    mrmovl  4(%eax), %eax
    rmmovl  %eax, 8(%ebp)

L2:
    irmovl  $0, %ecx
    mrmovl  8(%ebp), %edx
    subl    %ecx, %edx
    jne     L3
    mrmovl  -4(%ebp), %eax
    rrmovl  %esp, %ebp
    popl    %ebp
    halt #THIS DOESN'T BELONG. COMMENT OUT TO SEE BAD BEHAVIOR.
    ret

#linked list
.align  4
    ele1:
            .long   0x00a
            .long   ele2
    ele2:
            .long   0x0b0
            .long   ele3
    ele3:
            .long   0xc00
            .long   0


    .pos    0x300
    Stack:

Thanks for your help!

  • 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-22T03:28:25+00:00Added an answer on May 22, 2026 at 3:28 am

    This may or may not be the cause of the error, but I think you are tearing down the stack frame of sum_list incorrectly. You set it up as follows:

    pushl   %ebp  
    rrmovl  %esp, %ebp
    

    but then you tear it down like this:

    rrmovl  %esp, %ebp
    popl    %ebp
    

    Notice that you copy from %esp to %ebp in both cases, which is not correct since the teardown is supposed to undo what the setup does. Instead, try

    rrmovl  %ebp, %esp
    popl    %ebp
    

    or simply

    leave
    

    which does the same thing.

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

Sidebar

Related Questions

For homework, I was given the following 8 code fragments to analyze and give
I'm stumped by the following homework question for an algorithms class: Suppose that we
Following on from my recent question on Large, Complex Objects as a Web Service
Following on from this question what would be the best way to write a
Following techniques from 'Modern C++ Design', I am implementing a persistence library with various
Following on from the question asked by Mykroft Best way to handle input from
Following is some obviously-defective code for which I think the compiler should emit a
The answer to this sample homework problem is "1,000,000", but I do not understand
I have this homework problem where I need to use regex to remove every
Does anyone know an algorithm for the following problem: Given a undirected connected graph

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.