delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/01/23:45:22

From: "M. Schulter" <mschulter AT value DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: And another question...
Date: 2 Oct 1997 03:00:46 GMT
Organization: Value Net Internetwork Services Inc.
Lines: 42
Message-ID: <60v2ou$rqo$1@vnetnews.value.net>
References: <199710020003 DOT RAA19191 AT adit DOT ap DOT net>
NNTP-Posting-Host: value.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nate Eldredge <eldredge AT ap DOT net> wrote:

: The reason the ".align 4"'s are spread throughout the code is that the
: ".align" directive only aligns that part of the code. I.E. when the
: assembler is assembling, it has a location counter that keeps track of the
: address at which the code it assembles will be. When it sees a ".align X"
: directive, it increases the location counter to a multiple of X, thus making
: the next instruction or label be on an X-byte boundary.

Hi, there, and this is just to add a fine point on the meaning of the
number following '.align' -- hoping that I've understood the docs
correctly, and inviting correction.

According to the GAS docs,

info as pseudo align

when .align is invoked for the a.out format on the i386, the number
following the align statement specifies "the number of low-order
zero-level bits" required in the location counter after advancement. Thus

.align 1     2-byte alignment   xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxx0
.align 2     4-byte alignment   xxxx xxxx xxxx xxxx xxxx xxxx xxxx xx00
.align 3     8-byte alignment   xxxx xxxx xxxx xxxx xxxx xxxx xxxx x000
.align 4    16-byte alignment   xxxx xxxx xxxx xxxx xxxx xxxx xxxx 0000
.align n   2^n-byte alignment                     etc.

If I read and interpret correctly, then '.align 4' aligns on a 16-byte
boundary, which as mentioned elsewhere in your post helps to optimize on
systems such as the 486.

Anyway, thanks a great deal for the information about the advantages in
some cases of 16-byte alignment -- very valuable knowledge for an aspirant
to assembler. A friend and I were discussing the possible reasons for
using '.align 4' as opposed to '.align 2' -- which I've seen gcc use in
output from some simple C programs -- and you may have solved this
mystery.

Most appreciatively,

Margo Schulter
mschulter AT value DOT net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019