Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > BOOK: Professional Assembly Language
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Assembly Language
This is the forum to discuss the Wrox book Professional Assembly Language by Richard Blum; ISBN: 9780764579011
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Assembly Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 4th, 2010, 01:04 AM
Registered User
 
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Smile A basic assembly question

Hello, Sir

I am reading your book and I have a question to ask you.

In chapter 6, the "if statements" topic, you provide a example, the ifthen.c program .After convert the C code to assembly, it looks like as follow:
Code:
main:
        pushl   %ebp
        movl    %esp, %ebp
        andl    $-16, %esp
        subl    $32, %esp
        movl    $100, 24(%esp)
        movl    $20, 28(%esp)
        movl    24(%esp), %eax
        cmpl    28(%esp), %eax
        jle     .L2
        movl    $.LC0, %eax
        movl    24(%esp), %edx
        movl    %edx, 4(%esp)
        movl    %eax, (%esp)
        call    printf
        jmp     .L3
.L2:
        movl    $.LC0, %eax
        movl    28(%esp), %edx
        movl    %edx, 4(%esp)
        movl    %eax, (%esp)
        call    printf
.L3:
        movl    $0, %eax
        leave
        ret
I noticed that there are two assembly statements,
11 andl $-16, %esp
12 subl $32, %esp
in my opinion, these two statements could be instead by this statement,
subl %48, %esp.
I don't know why the gcc compiler use two statements rather than one. BTW, even the latest gcc compiler with O2 option, these two statements still exist.

Hope you reply.
Thank you very much!
Reply With Quote
  #2 (permalink)  
Old May 18th, 2010, 01:00 AM
Registered User
 
Join Date: Mar 2009
Location: Shanghai China
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default huh....

I also get confused
__________________
Code:
for ( int age = 17; age<25; ++age)
 cout<<"I am in Chengdu, China"<<endl;
for ( age = 25; age<30; ++age)
cout<<"I am in Shanghai, China"<<endl;
Reply With Quote
  #3 (permalink)  
Old December 23rd, 2012, 07:43 PM
Registered User
Points: 16, Level: 1
Points: 16, Level: 1 Points: 16, Level: 1 Points: 16, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

11 andl $-16, %esp
12 subl $32, %esp

it is used to align the memory of stack.
Reply With Quote
  #4 (permalink)  
Old December 25th, 2012, 06:29 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Austin, Tx.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To elaborate on what pengzhixi said:

Line 11 is used to mask off the lower 4 bits of ESP. $-16 in hex is 0xFFFFFFF0. This insures that the ESP register is an even multiple of 16, which can allow the processor to optimize the memory accesses.

Line 12 subtracts and additional 32 from the stack, presumably to make room for and locals that have been defined. Note that 32 is also a multiple of 16, and so the stack remains 16 byte aligned.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to emit assembly: Referenced assembly 'AxInterop.MSCommLib' does not have a s sanderson Visual Basic 2008 Essentials 1 July 16th, 2009 09:20 AM
Please HELP Very Basic Question jkoe578 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 18th, 2006 09:06 AM
basic xslt Question abhishek verma XSLT 4 January 24th, 2006 04:35 AM
basic question but..... Adam H-W Javascript How-To 2 February 10th, 2004 12:24 PM



All times are GMT -4. The time now is 11:48 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.