[GAS] Teil 2: Erklärung, clean the stack & diverses



  • Hey,

    da bin ich wieder.

    Zuerst möchte ich mal den ASM Code posten:
    (MACRO's)

    .MACRO _print message
     # start _print message
     pushl $\message
     call puts
     addl $4,%esp
     # end   _print message
     .ENDM
    
     .MACRO _open file mode
     # start _open file mode
     pushl %ebp
     movl %esp,%ebp
     pushl $\mode
     pushl $\file
     call fopen
     addl $8,%esp   << hier
     movl %eax,-4(%ebp)
     # %eax = file-handle
     #        - if %eax = 0 then the file doesn't exist
     #        - if %eax >< 0 %eax is the file-handle
     popl %ebp
     # end   _open file mode
     .ENDM
    
     .MACRO _close filehandle
     # start _close filehandle
     pushl \filehandle
     call fclose
     addl $4,%esp
     # end   _close filehandle
     .ENDM
    

    Wieso ist hier $8 und nicht $4.

    addl $8,%esp
    

    Wie ich auf $4 komme (ein ASM Beispiel davor):

    .text
    message:
     .ascii "Hello world!\0"
     .align 4
    .globl main
    main:
     pushl %ebp            
     movl %esp,%ebp
     #call ___main          
     pushl $message       
     call puts
     addl $4,%esp    <<< hier
     xorl %eax,%eax
     movl %ebp,%esp     
     popl %ebp
     ret
    

    Kann mir das jemand mal bitte (möglichst klar, ausführlich) erklären?

    und

    Was genau bedeutet das hier:

    movl %eax,-4(%ebp)
    

    vorallem das -4(%ebp) ist mir sehr unklar 🙂

    Und hier noch fopen (C-Referenz), Manpage:

    #include <stdio.h> 
    FILE *fopen(const char *path, const char *mode);
    

    Vielen Dank für eure Bemühungen und Gruss,
    unix]newbie,

    URL zum Bsp. http://www.janw.easynet.be/eng.html



  • Sorry für Doppelpost, ich weiss, dass es nicht gern gesehen wird, aber meine Hand konnte dem Submit-Button nicht widerstehen.

    Wenn wir grad dabei sind, das kapiere ich auch nicht:

    pushl %ebp 
     movl %esp,%ebp
    

    ebp ist klar
    esp ist instruction pointer, oder?

    Gruss unix]newbie


Anmelden zum Antworten