Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 4th, 2010, 02: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:
        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
        movl    $.LC0, %eax
        movl    28(%esp), %edx
        movl    %edx, 4(%esp)
        movl    %eax, (%esp)
        call    printf
        movl    $0, %eax
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!
Old May 18th, 2010, 01:00 AM
Registered User
Join Date: Mar 2009
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
Default huh....

I also get confused
Old December 23rd, 2012, 08:43 PM
Registered User
Join Date: Dec 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

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

it is used to align the memory of stack.
Old December 25th, 2012, 07:29 AM
Registered User
Join Date: Oct 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

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.

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 10:06 AM
basic xslt Question abhishek verma XSLT 4 January 24th, 2006 05:35 AM
basic question but..... Adam H-W Javascript How-To 2 February 10th, 2004 01:24 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.