Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 05-25-2013, 02:27 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › Assembly v
« Previous 1 2 3 Next »

porting kode c ke asm

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
porting kode c ke asm
08-06-2010, 12:59 AM
Post: #1
mywisdom Offline
Administrator
*******
Administrators
Posts: 921
Joined: Dec 2009
Reputation: 44
porting kode c ke asm
malloc()

sh-3.2# cat malloc.c
Code:
#include <stdlib.h>
int main()
{
int *pointer;
int i=0;
for (;;)
{
pointer=(int*) malloc(sizeof(int));
pointer=&i;
i++;
}
}

kompile :
Code:
gcc -S malloc.c

sh-3.2# cat malloc.s
Code:
.file   "malloc.c"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $20, %esp
        movl    $0, -12(%ebp)
.L2:
        movl    $4, (%esp)
        call    malloc
        movl    %eax, -8(%ebp)
        leal    -12(%ebp), %eax
        movl    %eax, -8(%ebp)
        movl    -12(%ebp), %eax
        addl    $1, %eax
        movl    %eax, -12(%ebp)
        jmp     .L2
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-48)"
        .section        .note.GNU-stack,"",@progbits


pagesize()

Code:
sh-3.2# cat page.c
int  getpagesize();
int main()
        {
int i=getpagesize();
        printf ("\nUkuran page adalah : %d\n",i);
}

Code:
gcc -S page.c


sh-3.2# cat page.s
Code:
.file   "page.c"
        .section        .rodata
.LC0:
        .string "\nUkuran page adalah : %d\n"
        .text
.globl main
        .type   main, @function
main:
        leal    4(%esp), %ecx
        andl    $-16, %esp
        pushl   -4(%ecx)
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ecx
        subl    $36, %esp
        call    getpagesize
        movl    %eax, -8(%ebp)
        movl    -8(%ebp), %eax
        movl    %eax, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf
        addl    $36, %esp
        popl    %ecx
        popl    %ebp
        leal    -4(%ecx), %esp
        ret
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-48)"
        .section        .note.GNU-stack,"",@progbits
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-25-2013, 02:27 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE