Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .section    .rodata
  2.     .align 8
  3. .jumpTable:
  4.     .quad   .option50
  5.     .quad   .option51
  6.     .quad   .option52
  7.     .quad   .option53
  8.     .quad   .option54
  9.     .quad   .defaultOption
  10.  
  11. strFormatForScanf:  .string "%c"
  12. str:            .string "In run_func\n"
  13. stringForStrlen:    .string "first pstring length: %d, second pstring length: %d\n"
  14. strForSwapCase:     .string "length: , string: %s\n"
  15.     ########
  16.     .text
  17. .global run_func
  18.     .type run_func,@function
  19. run_func:
  20.     pushq   %rbp        #save the old frame pointer
  21.     movq    %rsp,   %rbp    #create the new frame pointer
  22.     movq    %rsi, %r12  #save the first pstring in a caller saver register
  23.     movq    %rdx, %r13  #save the second pstring in a caller saver register
  24.  
  25.     subq $50, %rdi
  26.     cmpq $5, %rdi
  27.     ja  .defaultOption
  28.     jmp *.jumpTable(,%rdi,8)
  29.    
  30.      .option50:
  31.     movq    %r12, %rdi          #send the first pstring as a parameter to pstrlen
  32.     call    pstrlen
  33.     movq    %rax, %rsi          #move the return value into the second parameter for printf
  34.     movq    %r13, %rdi          #send the second pstring as a parameter to pstrlen
  35.     call    pstrlen
  36.     movq    %rax, %rdx          #move the return value into the thrid parameter to printf
  37.     movq    $stringForStrlen, %rdi      #save the string as the first parameter to printf
  38.     movq    $0, %rax
  39.     call    printf 
  40.     movq    $0, %rax
  41.     jmp .defaultOption
  42.  
  43.       .option51:
  44.     movq    %r12 ,%rdi
  45.     #call   replaceChar
  46.    
  47.     subq    $1, %rsp
  48.     movq    %rsp, %r14
  49.     subq    $1, %rsp
  50.     movq    %rsp, %r15
  51.        
  52.  
  53.     movq    $strFormatForScanf, %rdi    #first param to scanf
  54.     movq    %r14, %rsi
  55.     #subq   $2, %rsp            #increase the stack
  56.     #movq   1(%rsp), %rsi           #second param to scanf     
  57.     movq    $0, %rax
  58.     call    scanf
  59.     movq    $0, %rax
  60.     call    replaceChar
  61.  
  62.     #movq   $0, %rax   
  63.  
  64.     #movq   $delete, %rdi           #first param to printf
  65.     #movq   4(%rsp), %rsi           #second param to printf
  66.     #movq   $0, %rax
  67.     #call   printf
  68.     jmp .defaultOption
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement