Share Pastebin
Guest
Public paste!

inline C with Linked list implemtnation.

By: a guest | Mar 14th, 2010 | Syntax: ASM (NASM) | Size: 10.57 KB | Hits: 59 | Expires: Never
Copy text to clipboard
  1. GAS LISTING /tmp/cc0f9pg4.s                     page 1
  2.  
  3.  
  4.    1                            .file   "ll.c"
  5.    9                    .Ltext0:
  6.   10                            .comm   m,24,16
  7.   11                    .globl add
  8.   13                    add:
  9.   14                    .LFB0:
  10.   15                            .file 1 "ll.c"
  11.    0:ll.c          **** #include <stdio.h>
  12.    1:ll.c          **** #include <stdlib.h>
  13.    2:ll.c          ****
  14.    3:ll.c          **** struct e {
  15.    4:ll.c          ****         struct e *next;        
  16.    5:ll.c          ****         struct e *prev;
  17.    6:ll.c          ****         int count;
  18.    7:ll.c          **** } m;
  19.    8:ll.c          ****
  20.    9:ll.c          **** // in this case we add b.
  21.   10:ll.c          **** void add(struct e *x, struct e *y) {
  22.   16                            .loc 1 11 0
  23.   17                            .cfi_startproc
  24.   18 0000 55                    pushq   %rbp
  25.   19                            .cfi_def_cfa_offset 16
  26.   20 0001 4889E5                movq    %rsp, %rbp
  27.   21                            .cfi_offset 6, -16
  28.   22                            .cfi_def_cfa_register 6
  29.   23 0004 48897DF8              movq    %rdi, -8(%rbp)
  30.   24 0008 488975F0              movq    %rsi, -16(%rbp)
  31.   11:ll.c          ****
  32.   12:ll.c          ****         x->next->prev = y;
  33.   25                            .loc 1 13 0
  34.   26 000c 488B45F8              movq    -8(%rbp), %rax
  35.   27 0010 488B00                movq    (%rax), %rax
  36.   28 0013 488B55F0              movq    -16(%rbp), %rdx
  37.   29 0017 48895008              movq    %rdx, 8(%rax)
  38.   13:ll.c          ****         y->prev = x;
  39.   30                            .loc 1 14 0
  40.   31 001b 488B45F0              movq    -16(%rbp), %rax
  41.   32 001f 488B55F8              movq    -8(%rbp), %rdx
  42.   33 0023 48895008              movq    %rdx, 8(%rax)
  43.   14:ll.c          ****         y->next = x->next;
  44.   34                            .loc 1 15 0
  45.   35 0027 488B45F8              movq    -8(%rbp), %rax
  46.   36 002b 488B10                movq    (%rax), %rdx
  47.   37 002e 488B45F0              movq    -16(%rbp), %rax
  48.   38 0032 488910                movq    %rdx, (%rax)
  49.   15:ll.c          ****         x->next = y;
  50.   39                            .loc 1 16 0
  51.   40 0035 488B45F8              movq    -8(%rbp), %rax
  52.   41 0039 488B55F0              movq    -16(%rbp), %rdx
  53.   42 003d 488910                movq    %rdx, (%rax)
  54.   16:ll.c          ****
  55.   17:ll.c          **** }
  56.   43                            .loc 1 18 0
  57.   44 0040 C9                    leave
  58.   45                            .cfi_def_cfa 7, 8
  59.   46 0041 C3                    ret
  60.   47                            .cfi_endproc
  61. GAS LISTING /tmp/cc0f9pg4.s                    page 2
  62.  
  63.  
  64.   48                    .LFE0:
  65.   50                    .globl delete
  66.   52                    delete:
  67.   53                    .LFB1:
  68.   18:ll.c          ****
  69.   19:ll.c          ****
  70.   20:ll.c          **** // in this case we get b.
  71.   21:ll.c          **** void delete (struct e *x) {
  72.   54                            .loc 1 22 0
  73.   55                            .cfi_startproc
  74.   56 0042 55                    pushq   %rbp
  75.   57                            .cfi_def_cfa_offset 16
  76.   58 0043 4889E5                movq    %rsp, %rbp
  77.   59                            .cfi_offset 6, -16
  78.   60                            .cfi_def_cfa_register 6
  79.   61 0046 4883EC10              subq    $16, %rsp
  80.   62 004a 48897DF8              movq    %rdi, -8(%rbp)
  81.   22:ll.c          ****
  82.   23:ll.c          ****         x->prev->next = x->next;
  83.   63                            .loc 1 24 0
  84.   64 004e 488B45F8              movq    -8(%rbp), %rax
  85.   65 0052 488B4008              movq    8(%rax), %rax
  86.   66 0056 488B55F8              movq    -8(%rbp), %rdx
  87.   67 005a 488B12                movq    (%rdx), %rdx
  88.   68 005d 488910                movq    %rdx, (%rax)
  89.   24:ll.c          ****         x->next->prev = x->prev;
  90.   69                            .loc 1 25 0
  91.   70 0060 488B45F8              movq    -8(%rbp), %rax
  92.   71 0064 488B00                movq    (%rax), %rax
  93.   72 0067 488B55F8              movq    -8(%rbp), %rdx
  94.   73 006b 488B5208              movq    8(%rdx), %rdx
  95.   74 006f 48895008              movq    %rdx, 8(%rax)
  96.   25:ll.c          ****         free(x);        
  97.   75                            .loc 1 26 0
  98.   76 0073 488B45F8              movq    -8(%rbp), %rax
  99.   77 0077 4889C7                movq    %rax, %rdi
  100.   78 007a E8000000              call    free
  101.   78      00
  102.   26:ll.c          **** }
  103.   79                            .loc 1 27 0
  104.   80 007f C9                    leave
  105.   81                            .cfi_def_cfa 7, 8
  106.   82 0080 C3                    ret
  107.   83                            .cfi_endproc
  108.   84                    .LFE1:
  109.   86                            .section        .rodata
  110.   87                    .LC0:
  111.   88 0000 25642000              .string "%d "
  112.   89                            .text
  113.   90                    .globl show
  114.   92                    show:
  115.   93                    .LFB2:
  116.   27:ll.c          ****
  117.   28:ll.c          **** // show the list at the current point in time.
  118.   29:ll.c          **** void show( struct e *head ) {
  119.   94                            .loc 1 30 0
  120.   95                            .cfi_startproc
  121. GAS LISTING /tmp/cc0f9pg4.s                    page 3
  122.  
  123.  
  124.   96 0081 55                    pushq   %rbp
  125.   97                            .cfi_def_cfa_offset 16
  126.   98 0082 4889E5                movq    %rsp, %rbp
  127.   99                            .cfi_offset 6, -16
  128.  100                            .cfi_def_cfa_register 6
  129.  101 0085 4883EC20              subq    $32, %rsp
  130.  102 0089 48897DE8              movq    %rdi, -24(%rbp)
  131.   30:ll.c          ****
  132.   31:ll.c          ****         struct e *tmp
  133.   32:ll.c          ****         tmp = head;
  134.  103                            .loc 1 33 0
  135.  104 008d 488B45E8              movq    -24(%rbp), %rax
  136.  105 0091 488945F8              movq    %rax, -8(%rbp)
  137.  106                    .L6:
  138.   33:ll.c          ****
  139.   34:ll.c          ****         do {
  140.   35:ll.c          ****                 printf("%d " , tmp->count) ;
  141.  107                            .loc 1 36 0
  142.  108 0095 488B45F8              movq    -8(%rbp), %rax
  143.  109 0099 8B5010                movl    16(%rax), %edx
  144.  110 009c B8000000              movl    $.LC0, %eax
  145.  110      00
  146.  111 00a1 89D6                  movl    %edx, %esi
  147.  112 00a3 4889C7                movq    %rax, %rdi
  148.  113 00a6 B8000000              movl    $0, %eax
  149.  113      00
  150.  114 00ab E8000000              call    printf
  151.  114      00
  152.   36:ll.c          ****                 tmp = tmp->next;
  153.  115                            .loc 1 37 0
  154.  116 00b0 488B45F8              movq    -8(%rbp), %rax
  155.  117 00b4 488B00                movq    (%rax), %rax
  156.  118 00b7 488945F8              movq    %rax, -8(%rbp)
  157.   37:ll.c          ****         } while(tmp != NULL) ;
  158.  119                            .loc 1 38 0
  159.  120 00bb 48837DF8              cmpq    $0, -8(%rbp)
  160.  120      00
  161.  121 00c0 75D3                  jne     .L6
  162.   38:ll.c          ****
  163.   39:ll.c          ****         printf("\n");
  164.  122                            .loc 1 40 0
  165.  123 00c2 BF0A0000              movl    $10, %edi
  166.  123      00
  167.  124 00c7 E8000000              call    putchar
  168.  124      00
  169.   40:ll.c          ****
  170.   41:ll.c          **** }
  171.  125                            .loc 1 42 0
  172.  126 00cc C9                    leave
  173.  127                            .cfi_def_cfa 7, 8
  174.  128 00cd C3                    ret
  175.  129                            .cfi_endproc
  176.  130                    .LFE2:
  177.  132                    .globl main
  178.  134                    main:
  179.  135                    .LFB3:
  180.   42:ll.c          ****
  181. GAS LISTING /tmp/cc0f9pg4.s                    page 4
  182.  
  183.  
  184.   43:ll.c          **** int main(void) {
  185.  136                            .loc 1 44 0
  186.  137                            .cfi_startproc
  187.  138 00ce 55                    pushq   %rbp
  188.  139                            .cfi_def_cfa_offset 16
  189.  140 00cf 4889E5                movq    %rsp, %rbp
  190.  141                            .cfi_offset 6, -16
  191.  142                            .cfi_def_cfa_register 6
  192.  143 00d2 4883EC20              subq    $32, %rsp
  193.   44:ll.c          ****
  194.   45:ll.c          ****
  195.   46:ll.c          ****         struct e *a;
  196.   47:ll.c          ****         struct e *b;
  197.   48:ll.c          ****         struct e *c;
  198.   49:ll.c          ****
  199.   50:ll.c          ****         a = (struct e *) malloc(sizeof(struct e));
  200.  144                            .loc 1 51 0
  201.  145 00d6 BF180000              movl    $24, %edi
  202.  145      00
  203.  146 00db E8000000              call    malloc
  204.  146      00
  205.  147 00e0 488945E8              movq    %rax, -24(%rbp)
  206.   51:ll.c          ****         b = (struct e *) malloc(sizeof(struct e));
  207.  148                            .loc 1 52 0
  208.  149 00e4 BF180000              movl    $24, %edi
  209.  149      00
  210.  150 00e9 E8000000              call    malloc
  211.  150      00
  212.  151 00ee 488945F0              movq    %rax, -16(%rbp)
  213.   52:ll.c          ****         c = (struct e *) malloc(sizeof(struct e));
  214.  152                            .loc 1 53 0
  215.  153 00f2 BF180000              movl    $24, %edi
  216.  153      00
  217.  154 00f7 E8000000              call    malloc
  218.  154      00
  219.  155 00fc 488945F8              movq    %rax, -8(%rbp)
  220.   53:ll.c          ****        
  221.   54:ll.c          ****         a->count = 1;
  222.  156                            .loc 1 55 0
  223.  157 0100 488B45E8              movq    -24(%rbp), %rax
  224.  158 0104 C7401001              movl    $1, 16(%rax)
  225.  158      000000
  226.   55:ll.c          ****         b->count = 2;
  227.  159                            .loc 1 56 0
  228.  160 010b 488B45F0              movq    -16(%rbp), %rax
  229.  161 010f C7401002              movl    $2, 16(%rax)
  230.  161      000000
  231.   56:ll.c          ****         c->count = 3;
  232.  162                            .loc 1 57 0
  233.  163 0116 488B45F8              movq    -8(%rbp), %rax
  234.  164 011a C7401003              movl    $3, 16(%rax)
  235.  164      000000
  236.   57:ll.c          ****        
  237.   58:ll.c          ****         a->prev = NULL;
  238.  165                            .loc 1 59 0
  239.  166 0121 488B45E8              movq    -24(%rbp), %rax
  240.  167 0125 48C74008              movq    $0, 8(%rax)
  241. GAS LISTING /tmp/cc0f9pg4.s                    page 5
  242.  
  243.  
  244.  167      00000000
  245.   59:ll.c          ****         a->next = c;
  246.  168                            .loc 1 60 0
  247.  169 012d 488B45E8              movq    -24(%rbp), %rax
  248.  170 0131 488B55F8              movq    -8(%rbp), %rdx
  249.  171 0135 488910                movq    %rdx, (%rax)
  250.   60:ll.c          ****         c->prev = a;
  251.  172                            .loc 1 61 0
  252.  173 0138 488B45F8              movq    -8(%rbp), %rax
  253.  174 013c 488B55E8              movq    -24(%rbp), %rdx
  254.  175 0140 48895008              movq    %rdx, 8(%rax)
  255.   61:ll.c          ****
  256.   62:ll.c          ****         show(a);
  257.  176                            .loc 1 63 0
  258.  177 0144 488B45E8              movq    -24(%rbp), %rax
  259.  178 0148 4889C7                movq    %rax, %rdi
  260.  179 014b E8000000              call    show
  261.  179      00
  262.   63:ll.c          ****         // add b after a
  263.   64:ll.c          ****         add(a,b);
  264.  180                            .loc 1 65 0
  265.  181 0150 488B55F0              movq    -16(%rbp), %rdx
  266.  182 0154 488B45E8              movq    -24(%rbp), %rax
  267.  183 0158 4889D6                movq    %rdx, %rsi
  268.  184 015b 4889C7                movq    %rax, %rdi
  269.  185 015e E8000000              call    add
  270.  185      00
  271.   65:ll.c          ****        
  272.   66:ll.c          ****         show(a);
  273.  186                            .loc 1 67 0
  274.  187 0163 488B45E8              movq    -24(%rbp), %rax
  275.  188 0167 4889C7                movq    %rax, %rdi
  276.  189 016a E8000000              call    show
  277.  189      00
  278.   67:ll.c          ****
  279.   68:ll.c          ****         // delete b
  280.   69:ll.c          ****         delete(b);
  281.  190                            .loc 1 70 0
  282.  191 016f 488B45F0              movq    -16(%rbp), %rax
  283.  192 0173 4889C7                movq    %rax, %rdi
  284.  193 0176 E8000000              call    delete
  285.  193      00
  286.   70:ll.c          ****
  287.   71:ll.c          ****         show(a);
  288.  194                            .loc 1 72 0
  289.  195 017b 488B45E8              movq    -24(%rbp), %rax
  290.  196 017f 4889C7                movq    %rax, %rdi
  291.  197 0182 E8000000              call    show
  292.  197      00
  293.   72:ll.c          ****
  294.   73:ll.c          ****        
  295.   74:ll.c          ****
  296.   75:ll.c          **** }
  297.  198                            .loc 1 76 0
  298.  199 0187 C9                    leave
  299.  200                            .cfi_def_cfa 7, 8
  300.  201 0188 C3                    ret
  301. GAS LISTING /tmp/cc0f9pg4.s                    page 6
  302.  
  303.  
  304.  202                            .cfi_endproc
  305.  203                    .LFE3:
  306.  205                    .Letext0:
  307. GAS LISTING /tmp/cc0f9pg4.s                    page 7
  308.  
  309.  
  310. DEFINED SYMBOLS
  311.                             *ABS*:0000000000000000 ll.c
  312.                             *COM*:0000000000000018 m
  313.      /tmp/cc0f9pg4.s:13     .text:0000000000000000 add
  314.      /tmp/cc0f9pg4.s:52     .text:0000000000000042 delete
  315.      /tmp/cc0f9pg4.s:92     .text:0000000000000081 show
  316.      /tmp/cc0f9pg4.s:134    .text:00000000000000ce main
  317.  
  318. UNDEFINED SYMBOLS
  319. free
  320. printf
  321. putchar
  322. malloc