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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:55:46+00:00 2026-06-05T06:55:46+00:00

I am currently busy with assembly and ran into the following problem: I’m trying

  • 0

I am currently busy with assembly and ran into the following problem:

I’m trying to get a number that has been typed into the eax register. First i present a string which asks for input and then someone has to enter a number.

I’ve used the following code, but I don’t understand every bit of it. Please note the comments in the code.

I know absolutely nothing happens now with the number, except that is has been moved into eax. What i do want to know is why i must use leal: why and what does it do? and why do i need to push eax back on the stack?

.text
string1: .asciz "Please enter a number\n"
input: .asciz "%d" 

.global main
main:
       # Editor's note: this code is broken / unsafe; missing push %ebp here
  movl %esp, %ebp
  
  push $string1          # prompt string
  call printf            #print the string
           # no add $4, %esp here: 4 bytes still allocated on the stack

  leal -4(%ebp), %eax   # ????
  pushl %eax            # the thing you pushed in eax is now pushed on the stack?
  pushl $input          #the number 
  
  call scanf      
  
  popl %eax
  popl %eax       # the number that has been entered is now in eax
  
  call end
  
end:
  push $0
  call exit
  • 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-05T06:55:47+00:00Added an answer on June 5, 2026 at 6:55 am

    You are calling functions, so you pass parameters to them on the stack. One integer is returned to you in eax, rest is via input-output pointer parameters, again, on the stack. Check out x86 calling conventions.

    Edit 0:

    The leal instruction stores effective address of some temporary variable (that’s where scanf puts your integer value) into eax, then you pass it to scanf on the stack. Take a look here: What's the purpose of the LEA instruction?

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

Sidebar

Related Questions

I'm currently busy converting my code to ARC and ran into a little bit
Currently working with converting SQLException error messages into messages that are more useful for
I am currently busy creating a search function that queries a user input string
I have a busy photo website that has approximately 350,000 photos. The high resolution,
I'm currently busy with rewriting an application into MVVM (in stages, because it is
Basic problem: We are currently busy developing a C# MVC3 web application, and after
At school we are busy making a Spotify application. I am currently making an
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am trying to use a bunch of custom perl modules, test.pm as
I'm currently busy working on an IP ban tool for the early versions of

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.