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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:07:22+00:00 2026-05-20T20:07:22+00:00

I am reading a programming from the ground up, if you don’t know what

  • 0

I am reading a “programming from the ground up”, if you don’t know what this book is, you still can help me.

In this book(chapter 4) there are 2 things that I don’t understand:

  1. what movl %ebx, -4(%ebp) #store current result for.
  2. and what does “current result” means

in marked section in the code below, there is:

movl 8(%ebp), %ebx

which means save 8(%ebp) to %ebx, but the reason why I don’t understand is, if the programmer want 8(%ebp) to save to -4(%ebp), why should 8(%ebp) be passed through %ebx? Is “movl 8(%ebp), -4(%ebp)” akward? Or is there any typo in movl 8(%ebp), %ebx #put first argument in %eax?
(I think %ebx should be %eax or vice versa)

#PURPOSE: Program to illustrate how functions work
# This program will compute the value of
# 2^3 + 5^2
#Everything in the main program is stored in registers,
#so the data section doesn’t have anything.

.section .data
.section .text
.globl _start

_start:

pushl $3 #push second argument
pushl $2 #push first argument
call power #call the function
addl $8, %esp #move the stack pointer back
pushl %eax #save the first answer before

#calling the next function

pushl $2 #push second argument
pushl $5 #push first argument

call power #call the function
addl $8, %esp #move the stack pointer back
popl %ebx #The second answer is already

#in %eax. We saved the
#first answer onto the stack,
#so now we can just pop it
#out into %ebx

addl %eax, %ebx #add them together
#the result is in %ebx

movl $1, %eax #exit (%ebx is returned)
int $0x80

#PURPOSE: This function is used to compute
# the value of a number raised to
# a power.

#INPUT: First argument - the base number
# Second argument - the power to
# raise it to
#
#OUTPUT: Will give the result as a return value
#
#NOTES: The power must be 1 or greater
#
#VARIABLES:
# %ebx - holds the base number
# %ecx - holds the power
#
# -4(%ebp) - holds the current result
#
# %eax is used for temporary storage
#

.type power, @function
power:
pushl %ebp #save old base pointer
movl %esp, %ebp #make stack pointer the base pointer
subl $4, %esp #get room for our local storage
##########################################

movl 8(%ebp), %ebx #put first argument in %eax
movl 12(%ebp), %ecx #put second argument in %ecx
movl %ebx, -4(%ebp) #store current result

##########################################

power_loop_start:
cmpl $1, %ecx #if the power is 1, we are done
je end_power
movl -4(%ebp), %eax #move the current result into %eax
imull %ebx, %eax #multiply the current result by

#the base number
movl %eax, -4(%ebp) #store the current result
decl %ecx #decrease the power
jmp power_loop_start #run for the next power

end_power:
movl -4(%ebp), %eax #return value goes in %eax
movl %ebp, %esp #restore the stack pointer
popl %ebp #restore the base pointer
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-05-20T20:07:23+00:00Added an answer on May 20, 2026 at 8:07 pm

    I believe that this:

     movl 8(%ebp), %ebx #put first argument in %eax  
    

    was a typo, and it should really be:

     movl 8(%ebp), %ebx #put first argument in %ebx  
    

    and if you noticed, later the code is correct:

     movl %ebx, -4(%ebp) #store current result
    

    In the end, the author could have used %eax for this operation as well (instead of %ebx), there’s no reason why he shouldn’t since it wouldn’t change the program at all.

    But the comment could be a lot clearer and I believe that this is a typo as well. At this point, it would be better if it said: #storing 1st argument on the local stack frame.

    label power_loop_start uses that variable and temporarily stores it in %eax for quick operations and then place it back on the same location on the stack for the next loop:

     movl %eax, -4(%ebp)   #store the current result
     decl %ecx             #decrease the power
     jmp  power_loop_start #run for the next power
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading the book from Andrei Alexandrescu about the D programming language. He's
I was reading a book on programming skills wherein the author asks the interviewee,
I'm new to Windows programming and after reading the Petzold book I wonder: is
I did some programming for reading the data from Active Directory such as user
Today I was doing the thread ring exercise from the Programming Erlang book and
I am reading chapter 2 of Advanced Linux Programming: http://www.advancedlinuxprogramming.com/alp-folder/alp-ch02-writing-good-gnu-linux-software.pdf In the section 2.1.3
I was reading this excellent article which gives an introduction to Asynchronous programming here
I am looking for some libraries in delphi to programming and reading from RFID
I'm having trouble running the 3n+1 Problem from the Programming Challenges book . I've
I have just been getting into low level programming (reading/writing to memory that sort

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.