Simple assembly code on AIX - Aix

This is a discussion on Simple assembly code on AIX - Aix ; I want to learn how to write assembly code on AIX, and would like to write something like "helloworld" by assembly on AIX. I searched in google for a long time, but I only find some reference for assembly on ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

Thread: Simple assembly code on AIX

  1. Simple assembly code on AIX


    I want to learn how to write assembly code on AIX, and would like to write
    something like "helloworld" by assembly on AIX.

    I searched in google for a long time, but I only find some reference for
    assembly on AIX, not what I want.

    I do not find any simple example on assembly code on AIX, and could be
    compiled as an executable. I know how to do this in Linux, but I am a
    newbie on AIX.

    Could you anyone here help me? Thanks in advance.

    --
    Yao Qi GNU/Linux Developer
    http://duewayqi.googlepages.com/

    "I assure you the thought never even crossed my mind, lord."
    "Indeed? Then if I were you I'd sue my face for slander."
    -- Terry Pratchett, "The Colour of Magic"

  2. Re: Simple assembly code on AIX

    On 2007-04-30, Yao Qi wrote:
    >
    > I want to learn how to write assembly code on AIX, and would like to write
    > something like "helloworld" by assembly on AIX.
    >
    > I searched in google for a long time, but I only find some reference for
    > assembly on AIX, not what I want.
    >
    > I do not find any simple example on assembly code on AIX, and could be
    > compiled as an executable. I know how to do this in Linux, but I am a
    > newbie on AIX.
    >
    > Could you anyone here help me? Thanks in advance.


    I've no personal experience with this part of the AIX documentation,
    but maybe you'll find it helpfull:

    http://publib.boulder.ibm.com/infoce...f/alangref.htm

    Regards,

    Frank

  3. Re: Simple assembly code on AIX

    Frank Fegert writes:

    >>
    >> Could you anyone here help me? Thanks in advance.

    >
    > I've no personal experience with this part of the AIX documentation,
    > but maybe you'll find it helpfull:
    >
    > http://publib.boulder.ibm.com/infoce...f/alangref.htm


    Frank, thanks for your information.

    I am familiar with the instruction set of POWER, and write some assembly
    code on Linux. However, I find that it is different when I write
    assembly code on AIX, because the executable format is COFF.

    If there is a simple example, that would be great.
    >
    > Regards,
    >
    > Frank


    --
    Yao Qi GNU/Linux Developer
    http://duewayqi.googlepages.com/

    "Computers may be stupid, but they're always obedient. Well, almost always."

    -- Larry Wall (Open Sources, 1999 O'Reilly and Associates)

  4. Re: Simple assembly code on AIX

    Yao Qi wrote:
    > Frank Fegert writes:
    >
    >>> Could you anyone here help me? Thanks in advance.

    >> I've no personal experience with this part of the AIX documentation,
    >> but maybe you'll find it helpfull:
    >>
    >> http://publib.boulder.ibm.com/infoce...f/alangref.htm

    >
    > Frank, thanks for your information.
    >
    > I am familiar with the instruction set of POWER, and write some assembly
    > code on Linux. However, I find that it is different when I write
    > assembly code on AIX, because the executable format is COFF.
    >
    > If there is a simple example, that would be great.
    >> Regards,
    >>
    >> Frank

    >

    This?
    http://www-128.ibm.com/developerwork...library/l-ppc/

  5. Re: Simple assembly code on AIX

    Yao Qi writes:

    > I want to learn how to write assembly code on AIX, and would like to write
    > something like "helloworld" by assembly on AIX.


    The easiest way to obtain an example is to compile helloworld.c
    into assembly (with '-S' flag) and examine the result.

    This also allows you to make easy experiments:
    - how are locals accessed?
    - how are globals accessed?
    - what do string literals look like?
    - what happens when I change 'int x = 42;' into 'const int x = 42;'?
    .... etc ... etc.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  6. Re: Simple assembly code on AIX

    Paul Pluzhnikov writes:

    > Yao Qi writes:
    >
    >> I want to learn how to write assembly code on AIX, and would like to

    > write
    >> something like "helloworld" by assembly on AIX.

    >
    > The easiest way to obtain an example is to compile helloworld.c
    > into assembly (with '-S' flag) and examine the result.


    I did it some days ago as my homework, and this experiment could tell me
    a lot of things.

    Maybe I did not describe my question clear here, I want to write an
    assembly code *without* the link to libc or other system library.

    I could write PPC32 assembly on Linux, like in

    http://www-128.ibm.com/developerworks/library/l-ppc/

    How could I do the same thing in AIX?
    >
    > This also allows you to make easy experiments:
    > - how are locals accessed?
    > - how are globals accessed?
    > - what do string literals look like?
    > - what happens when I change 'int x = 42;' into 'const int x = 42;'?
    > ... etc ... etc.
    >
    > Cheers,


    --
    Yao Qi GNU/Linux Developer
    http://duewayqi.googlepages.com/

  7. Re: Simple assembly code on AIX

    Yao Qi writes:

    > Maybe I did not describe my question clear here, I want to write an
    > assembly code *without* the link to libc or other system library.


    You can't: unlike Linux, AIX does not provided a "fixed" syscall
    interface.

    The interface to the OS is specified at the libc.a, and you *have*
    to use that interface, or your executable will not be portable to
    future AIX releases (possibly including minor patch updates).

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  8. Re: Simple assembly code on AIX

    Paul Pluzhnikov wrote:
    > Yao Qi writes:
    >
    >> Maybe I did not describe my question clear here, I want to write an
    >> assembly code *without* the link to libc or other system library.

    >
    > You can't: unlike Linux, AIX does not provided a "fixed" syscall
    > interface.
    >
    > The interface to the OS is specified at the libc.a, and you *have*
    > to use that interface, or your executable will not be portable to
    > future AIX releases (possibly including minor patch updates).
    >
    > Cheers,


    Interesting... so you cannot just load registers and invoke a system
    trap (as in Solaris/sparc for example)? Why this interface design?

    john
    (Reply without ado)

  9. Re: Simple assembly code on AIX

    john o goyo wrote:
    > Paul Pluzhnikov wrote:
    >> Yao Qi writes:
    >>
    >>> Maybe I did not describe my question clear here, I want to write an
    >>> assembly code *without* the link to libc or other system library.

    >>
    >> You can't: unlike Linux, AIX does not provided a "fixed" syscall
    >> interface.
    >>
    >> The interface to the OS is specified at the libc.a, and you *have*
    >> to use that interface, or your executable will not be portable to
    >> future AIX releases (possibly including minor patch updates).
    >>
    >> Cheers,

    >
    > Interesting... so you cannot just load registers and invoke a system
    > trap (as in Solaris/sparc for example)? Why this interface design?
    >
    > john
    > (Reply without ado)


    "or your executable will not be portable to future AIX releases"

    IBM wants you to stay away from actually addressing the hardware.
    They make changes to the "allowable" instruction set as they decide
    what works best (performance? price?) and what doesn't so that
    programs compiled for older power platform with AIX version 3
    no longer worked on the later CPU's without recompiling.

    There are compiler settings to specify the target power CPU as well
    as a common instruction set that works on all CPU's.





  10. Re: Simple assembly code on AIX

    sol gongola schrieb:

    >
    > "or your executable will not be portable to future AIX releases"
    >
    > IBM wants you to stay away from actually addressing the hardware.
    > They make changes to the "allowable" instruction set as they decide
    > what works best (performance? price?) and what doesn't so that
    > programs compiled for older power platform with AIX version 3
    > no longer worked on the later CPU's without recompiling.
    >


    IIRC there was sort of a break between AIX 3.1 and 3.2,
    when one needed to recompile.
    Since 3.2, most if not all stuff is upward compatible.
    I still have binaries created around as early as 1992,
    which still run on the latest AIX.
    This is one of the reasons why one might prefer AIX
    over other platforms, and the IBM compilers over gcc.



  11. Re: Simple assembly code on AIX

    Michael Kraemer writes:

    > IIRC there was sort of a break between AIX 3.1 and 3.2,
    > when one needed to recompile.
    > Since 3.2, most if not all stuff is upward compatible.


    So long as it is dynamically linked against libc.a.

    (Some) completely-static executables fail when moved from 4.1 to
    4.2 to 5.1 ...

    > I still have binaries created around as early as 1992,
    > which still run on the latest AIX.
    > This is one of the reasons why one might prefer AIX
    > over other platforms, and the IBM compilers over gcc.


    I have binaries created in 1987 for SunOS 4 which still run just
    fine on Solaris 10.

    And 'gcc' vs. 'xlc' has absolutely nothing to do with this at all.
    You can create protable (dynamically linked) or non-portable
    (statically linked) executables with either.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  12. Re: Simple assembly code on AIX

    john o goyo writes:

    > Paul Pluzhnikov wrote:


    >> The interface to the OS is specified at the libc.a, and you *have*
    >> to use that interface...

    >
    > Interesting... so you cannot just load registers and invoke a system
    > trap (as in Solaris/sparc for example)? Why this interface design?


    It allows the kernel to support different set of 'system traps'
    on different hardware, and for the cheaper (less functional)
    hardware to emulate the more functional one.

    Also, virtualizing an instance of the OS is much easier if you can
    just "swap in" a different libc.a into the "guest" os and do not
    have to emulate all of the 'system traps'.

    Also, it allows for different methods of entering the supervisor
    mode (there are 'sc' and 'svc' instructions).

    The same problem exists on x86 -- 'int80' is faster on some
    processors, 'sysenter' on others), and glibc and the Linux kernel go
    through some trouble to dynamically select the faster method. But
    programs hard-coded to use direct 'int80' can't take advantage
    of that.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  13. Re: Simple assembly code on AIX

    Paul Pluzhnikov schrieb:

    >
    > So long as it is dynamically linked against libc.a.
    >
    > (Some) completely-static executables fail when moved from 4.1 to
    > 4.2 to 5.1 ...


    I was referring to the default usage of 'cc' etc.
    Surely one can make things break.

    >
    >
    > I have binaries created in 1987 for SunOS 4 which still run just
    > fine on Solaris 10.


    Created for 68k ?

    >
    > And 'gcc' vs. 'xlc' has absolutely nothing to do with this at all.
    > You can create protable (dynamically linked) or non-portable
    > (statically linked) executables with either.


    It's related. I seem to remenber gcc or gcc-created executables
    which used to break when used on a higher version of AIX.
    And there are gcc-created executables which refuse to run because they
    apparently miss some dynamic library.
    This doesn't happen with xlc, because
    the appropriate libs are always there.



  14. Re: Simple assembly code on AIX

    Michael Kraemer wrote:
    > sol gongola schrieb:
    >
    >>
    >> "or your executable will not be portable to future AIX releases"
    >>
    >> IBM wants you to stay away from actually addressing the hardware.
    >> They make changes to the "allowable" instruction set as they decide
    >> what works best (performance? price?) and what doesn't so that
    >> programs compiled for older power platform with AIX version 3
    >> no longer worked on the later CPU's without recompiling.
    >>

    >
    > IIRC there was sort of a break between AIX 3.1 and 3.2,
    > when one needed to recompile.
    > Since 3.2, most if not all stuff is upward compatible.
    > I still have binaries created around as early as 1992,
    > which still run on the latest AIX.
    > This is one of the reasons why one might prefer AIX
    > over other platforms, and the IBM compilers over gcc.
    >
    >

    The actual hardware instruction set changed. Some instructions
    were dropped, some new ones appeared. The compilers have an
    option to specify the target architure or a common one using
    machine instructions available on all the cpus.

    If you write code in assembly, it may not work on all processors.
    A higher level language you may only have to recompile.

    From xlc c compiler command (xlf fortran compiler has similar options):

    arch=

  15. Re: Simple assembly code on AIX

    In article , sol gongola writes:
    > The actual hardware instruction set changed.


    not between AIX 3.1 and 3.2. That was sth different.
    Another example coming to mind are threads
    (DCE in 3.2, Posix in 4.1). These are the only examples
    I can remember where you had no choice but to recompile
    and run two different versions of your binaries.

    > Some instructions
    > were dropped, some new ones appeared. The compilers have an
    > option to specify the target architure or a common one using
    > machine instructions available on all the cpus.


    Compilers do not help here if instructions are dropped
    and backward compatibility is the prime directive.
    AIX's run time environment must "somehow" emulate the missing
    instructions.

  16. Re: Simple assembly code on AIX

    Michael Kraemer writes:

    > Paul Pluzhnikov schrieb:
    >
    >> I have binaries created in 1987 for SunOS 4 which still run just
    >> fine on Solaris 10.

    >
    > Created for 68k ?


    SPARC. My bad. s/1987/1991/g

    My executable could have been compiled in 1987 for SPARC, but I
    didn't start working on SPARCs until 1991.

    > And there are gcc-created executables which refuse to run because they
    > apparently miss some dynamic library.


    You can hardly blaim 'gcc' for that. It is *your* responsibility
    to install all the shared libraries your program depends on, or to
    build without such dependencies.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  17. Re: Simple assembly code on AIX

    Paul Pluzhnikov schrieb:

    > And 'gcc' vs. 'xlc' has absolutely nothing to do with this at all.
    > You can create protable (dynamically linked) or non-portable
    > (statically linked) executables with either.


    It is possible to link portable and mostly statically linked executables
    with GCC. You have to statically link all you own stuff and _carefully_
    exclude libc.a
    this is nearly impossible with autogenerated libtoolized stuff with a
    GCC build the way, GCC is designed to build on AIX :-/

    This is much easier with the IBM compilers from VAC 5 onwards.

    The magic flag is often -blibpath:

    this can easily verified with a simple "dump -H" on the binary of
    Adobe's Acrobat Reader 4.05 as a bad example.

    Shared libs on AIX is different to shared libs on Linux or Solaris.
    Different does not imply worse or better. Only different.
    Using the GNU auto* tools this difference often implies major pain.
    The build system of perl shows how it can be done on AIX the AIX' way.

    --
    Uli

    http://www.linkitup.de/ForAIX/Firefox

  18. Re: Simple assembly code on AIX

    On 2007-05-04, Uli Link wrote:
    > this is nearly impossible with autogenerated libtoolized stuff with a
    > GCC build the way, GCC is designed to build on AIX :-/
    >
    > This is much easier with the IBM compilers from VAC 5 onwards.
    >
    > The magic flag is often -blibpath:


    I agree that libtool on AIX is one major pain, especially if
    you're doing staged installs in e.g. DESTDIR or similar. But
    i can't really see, whats the advantage of the VACs '-blibpath'
    vs. the GCCs '-Wl,-blibpath'. Could you please elaborate? Also
    i'd like to know what's wrong with the GCC build for AIX?

    > this can easily verified with a simple "dump -H" on the binary of
    > Adobe's Acrobat Reader 4.05 as a bad example.


    Could you please post the output?

    > Shared libs on AIX is different to shared libs on Linux or Solaris.
    > Different does not imply worse or better. Only different.
    > Using the GNU auto* tools this difference often implies major pain.
    > The build system of perl shows how it can be done on AIX the AIX' way.


    You may have a point, but - no offense - why not try to get
    the autotools/libtool fixed in a way they produce sane out-
    put on AIX? The other way round, i.e. building large software
    packages w/o auto*/libtool seems much more time-consuming, if
    possible at all ...

    Thanks & Regards,

    Frank

  19. Re: Simple assembly code on AIX

    Paul Pluzhnikov writes:

    > Yao Qi writes:
    >
    >> Maybe I did not describe my question clear here, I want to write an
    >> assembly code *without* the link to libc or other system library.

    >
    > You can't: unlike Linux, AIX does not provided a "fixed" syscall
    > interface.
    >
    > The interface to the OS is specified at the libc.a, and you *have*
    > to use that interface, or your executable will not be portable to
    > future AIX releases (possibly including minor patch updates).


    We want to write a small executable file with few instructions, so that
    we could verify the binary instrumentation done by our tool.

    It seems that I could not do it in this way. Thanks for your help.

    --
    Yao Qi GNU/Linux Developer
    http://duewayqi.googlepages.com/

    Don't Worry, Be Happy.
    -- Meher Baba

  20. Re: Simple assembly code on AIX

    Frank Fegert schrieb:
    >
    > I agree that libtool on AIX is one major pain, especially if
    > you're doing staged installs in e.g. DESTDIR or similar. But
    > i can't really see, whats the advantage of the VACs '-blibpath'
    > vs. the GCCs '-Wl,-blibpath'. Could you please elaborate? Also
    > i'd like to know what's wrong with the GCC build for AIX?


    '-Wl,-blibpath' is same flag passed to ld.
    The difference is the inclusion of the c++ lib.
    GCC builds this lib in many versions for different processor
    architectures in GCC configuration time specific places.
    So if you follow the general advice to link libs shared, you'll usually
    need the right version in the right place.

    Building staged installs is a MUST not only a "nice to have". I remember
    I had to compile as root, because I gmake install failed else.
    Not every production machine has a GCC (+ the whole GNU toolchain) build
    exactly the same way as the build host

    >> this can easily verified with a simple "dump -H" on the binary of
    >> Adobe's Acrobat Reader 4.05 as a bad example.


    >
    > Could you please post the output?
    >


    $ pwd
    /usr/lpp/Acrobat4/Reader/rs6000aix/bin
    $ dump -H acroread

    acroread:

    ***Loader Section***
    Loader Header Information
    VERSION# #SYMtableENT #RELOCent LENidSTR
    0x00000001 0x00000245 0x0000e827 0x0000012c

    #IMPfilID OFFidSTR LENstrTBL OFFstrTBL
    0x00000007 0x000b186c 0x000020e2 0x000b1998


    ***Import File Strings***
    INDEX PATH BASE MEMBER

    0
    lib:/user/unibat/Build/Root/shm/EXPORT:/user/scheung/aixtools/gcc/lib/gcc-lib/rs6000-ibm-aix4.2.1.0/2.8.1:/user/scheung/aixtools/gcc/rs6000-ibm-aix4.2.1.0/lib:/user/scheung/aixtools/gcc/lib:/usr/lib:/lib

    1 libc.a shr.o

    2 libXt.a shr4.o

    3 libC.a shr.o

    4 libX11.a shr4.o

    5 libXext.a shr.o

    6 libXm.a shr4.o

    $


    a simple -blibpath:/usr/lib:/lib would look much better and give shorter
    startup times.

    Here is the output of my fixed own package:
    acroread:

    ***Loader Section***
    Loader Header Information
    VERSION# #SYMtableENT #RELOCent LENidSTR
    0x00000001 0x0000024c 0x0000e831 0x0000006e

    #IMPfilID OFFidSTR LENstrTBL OFFstrTBL
    0x00000007 0x000b198c 0x000021cb 0x000b19fa


    ***Import File Strings***
    INDEX PATH BASE MEMBER

    0 /usr/lib:/lib

    1 libXt.a shr4.o

    2 libc.a shr.o

    3 libX11.a shr4.o

    4 libC.a shr.o

    5 libXext.a shr.o

    6 libXm.a shr4.o

    $

    the luck was, the original binary wasn't stripped. So I could relink it
    on AIX 4.1.5, so it was running on every RS/6000 with AIX 4 or higher.


    > You may have a point, but - no offense - why not try to get
    > the autotools/libtool fixed in a way they produce sane out-
    > put on AIX?


    Sorry, I tried to understand where to fix by reading the documentation.
    I wasn't able to find how and where. All I found was a 100k generated
    shell script and a build process spending more time in this shell script
    than in the compilers optimizer ;-)

    I stopped using GCC on AIX and got VisualAge C++ 5.02.

    --
    Uli

    recent Firefox and Seamonkey builds are coming soon!
    http://www.linkitup.de/ForAIX/Firefox

+ Reply to Thread
Page 1 of 2 1 2 LastLast