delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/31/15:24:46

From: Niklas_Pson AT nosmam DOT hotmail DOT com (Niklas Pettersson)
Newsgroups: comp.os.msdos.djgpp
Subject: Another align question
Date: 31 Jul 2001 18:54:52 GMT
Organization: Lund Institute of Technology, Sweden
Lines: 138
Message-ID: <90EFDC811NiklasPsonnospamhotm@130.235.20.4>
NNTP-Posting-Host: npedt97.univ.vxu.se
User-Agent: Xnews/03.04.11
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi!

I'm wrote a little program that tries to align all functions on 16 byte 
boundaries. I wan't to have "nop"'s between the functions (doesn't realy 
matter in this example but I want this for other purposes). The alignment 
is always correct but the "padding byte (0x90)" seems only to work with 
.balignl and .balignw (not with .balign). The code and disassembly is 
attached to the message. Can someone please tell me how to get the effect 
I'm looking for (without using .balign(w|l))

/ Niklas

.text

/*
 * Make functions visible to linker
 */
.globl  _func1
.globl  _func2
.globl  _func3
.globl  _func4

/*
 * Function aligned to a 16 byte boundary.
 */
.balign 16
_func1:
                pushl   %ebp
                movl    %esp, %ebp

                popl    %ebp

/* Padd so alignment below will work */

					 nop
                nop
					 nop

                ret

/*
 * Function aligned to a 16 byte boundary. Fill with nop (4 bytes at once)
 */
.balignl 16, 0x90909090
_func2:
                pushl   %ebp
                movl    %esp, %ebp

                popl    %ebp

/* Padd so alignment below will work */

					 nop

                ret

/*
 * Function aligned to a 16 byte boundary. Fill with nop (2 bytes at once)
 */
.balignw 16, 0x9090
_func3:
                pushl   %ebp
                movl    %esp, %ebp

                popl    %ebp

                ret

/*
 * Function aligned to a 16 byte boundary. Fill with nop (1 byte at once)
 */
.balign 16, 0x90
_func4:
                pushl   %ebp
                movl    %esp, %ebp

                popl    %ebp

                ret


This is the output (pasted in from GDB)

0x1570 <func1>: 	push   %ebp
0x1571 <func1+1>:       mov    %esp,%ebp
0x1573 <func1+3>:       pop    %ebp
0x1574 <func1+4>:       nop
0x1575 <func1+5>:       nop
0x1576 <func1+6>:       nop
0x1577 <func1+7>:       ret

/* This padding is correct! (used balignl) */
0x1578 <func1+8>:       nop
0x1579 <func1+9>:       nop
0x157a <func1+10>:      nop
0x157b <func1+11>:      nop
0x157c <func1+12>:      nop
0x157d <func1+13>:      nop
0x157e <func1+14>:      nop
0x157f <func1+15>:      nop

0x1580 <func2>: 	push   %ebp
0x1581 <func2+1>:       mov    %esp,%ebp
0x1583 <func2+3>:       pop    %ebp
0x1584 <func2+4>:       nop
0x1585 <func2+5>:       ret

/* This padding is correct! (used balignw) */
0x1586 <func2+6>:       nop
0x1587 <func2+7>:       nop
0x1588 <func2+8>:       nop
0x1589 <func2+9>:       nop
0x158a <func2+10>:      nop
0x158b <func2+11>:      nop
0x158c <func2+12>:      nop
0x158d <func2+13>:      nop
0x158e <func2+14>:      nop
0x158f <func2+15>:      nop

0x1590 <func3>: 	push   %ebp
0x1591 <func3+1>:       mov    %esp,%ebp
0x1593 <func3+3>:       pop    %ebp
0x1594 <func3+4>:       ret

/* This padding is NOT correct! (used balign) (well padding is correct but 
not fill byte) */
0x1595 <func3+5>:       lea    0x0(%esi,1),%esi
0x1599 <func3+9>:       lea    0x0(%edi,1),%edi

0x15a0 <func4>: 	push   %ebp
0x15a1 <func4+1>:       mov    %esp,%ebp
0x15a3 <func4+3>:       pop    %ebp
0x15a4 <func4+4>:       ret

0x15a5 <func4+5>:       lea    0x0(%esi,1),%esi
0x15a9 <func4+9>:       lea    0x0(%edi,1),%edi

Main goes here...

- Raw text -


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