SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .globl _start
  2. .text
  3. _start:
  4.     call parse_args
  5.    
  6.     mov $file, %rdi
  7.     call open_file
  8.     mov %rax, %rdi
  9.     call read_file
  10.     mov %rax, %r12
  11.     mov $0, %r9
  12.     mov $byte, %r13
  13.     movb (%r13), %al
  14.  
  15.     sub $48, %al
  16. loop:
  17.     mov $buffer, %r10
  18.     add %r9, %r10  
  19.     inc %r9
  20.     movb (%r10), %cl
  21.     xor %al, %cl
  22.     movb %cl, (%r10)
  23.     cmp %r9, %r12
  24.     jne loop
  25.     mov %r12, %rdi
  26.     call print_buf
  27. labab:
  28.     mov $60, %rax
  29.     syscall
  30.  
  31. print_buf:
  32.     mov $1, %rax
  33.     mov $1, %rdi
  34.     mov $buffer, %rsi
  35.     syscall
  36.     ret
  37.  
  38. open_file:
  39.     mov $2, %rax
  40.     mov $0, %rsi
  41.     syscall
  42.     ret
  43.  
  44. read_file:
  45.     mov $0, %rax
  46.     mov $buffer, %rsi
  47.     mov $bufferlen, %rdx
  48.     syscall
  49.     ret
  50.  
  51. parse_args:
  52.     pop %r8
  53.     pop %r9
  54.     pop %r10
  55.     cmp $1, %r9
  56.     je end_parse_args
  57.     dec %r9
  58. l1:
  59.     pop %r10
  60.     pop %r15
  61.  
  62.     cmp $0, %r10
  63.     je end_parse_args
  64.  
  65.     mov %r10, %r13
  66.     mov $file_str, %r14
  67.     mov $4, %r12
  68.    
  69.     push %r10
  70.     push %r15
  71.     call cmp_string
  72.     pop %r15
  73.     pop %r10
  74.  
  75.     cmp $1, %r11
  76.     je save_file
  77.  
  78.     mov %r10, %r13
  79.     mov $byte_str, %r14
  80.     mov $4, %r12
  81.    
  82.     push %r10
  83.     push %r15
  84.     call cmp_string
  85.     pop %r15
  86.     pop %r10
  87.  
  88.     cmp $1, %r11
  89.     je save_byte
  90.  
  91.     mov %r10, %r13
  92.     mov $destination_str, %r14
  93.     mov $4, %r12
  94.    
  95.     push %r10
  96.     push %r15
  97. l3:
  98.     call cmp_string
  99.     pop %r15
  100.     pop %r10
  101.  
  102.     cmp $1, %r11
  103.     je save_dest
  104.    
  105.     dec %r9
  106.     dec %r9
  107.     cmp $0, %r9
  108.     jne l1
  109.  
  110. end_parse_args:
  111.     push %r8
  112.     ret
  113.    
  114.  
  115. save_file:
  116.     mov $file, %r14
  117.     mov (%r15), %rax
  118.     mov %rax, (%r14)
  119.     jmp l1
  120. save_byte:
  121.     mov $byte, %r14
  122.     mov (%r15), %rax
  123.     mov %rax, (%r14)
  124.     jmp l1
  125. save_dest:
  126.     mov $dest, %r14
  127.     mov (%r15), %rax
  128.     mov %rax, (%r14)
  129.     jmp l1
  130.  
  131.  
  132. cmp_string:
  133.     movb (%r13), %al
  134.     cmp (%r14), %al
  135.     jne cmp_string_ne_exit
  136.     inc %r13
  137.     inc %r14
  138.     dec %r12
  139.     cmp $0, %r12
  140.     jne cmp_string
  141.     mov $1, %r11
  142.     ret
  143.  
  144. cmp_string_ne_exit:
  145.     mov $0, %r11
  146.     ret
  147.  
  148.  
  149.  
  150. .data
  151.     counter = 0
  152.     file_str: .ascii "file"
  153.     byte_str: .ascii "byte"
  154.     destination_str: .ascii "dest"
  155.     file: .fill 1024, 1, 0
  156.     byte: .byte 0
  157.     dest: .fill 1024, 1, 0
  158.     buffer: .fill 10000, 1, 0
  159.     bufferlen = 10000
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top