Advertisement
Coriic

Untitled

Jun 25th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     mask:
  3.     .long 0,0,0,0,0,0,0,0,0
  4.  
  5. .text
  6. .type encode, %function
  7. .global encode
  8.  
  9. #rdi - buf
  10. #rsi - maska
  11. #rdx - operacja
  12. #rcx - character
  13. encode:
  14.     PUSH %rbx
  15.     PUSH %rdi
  16.     PUSH %rsi
  17.     MOV $0, %rbx
  18. createMask:
  19.     PUSH %rsi
  20.     AND $1, %rsi
  21.     CMP $1, %rsi
  22.     JE changeMask
  23.     MOVL $0, mask(, %rbx, 4)
  24. maskChanged:
  25.     POP %rsi
  26.     SHR $1, %rsi
  27.     INC %rbx
  28.     CMP $10, %rbx
  29.     JNE createMask
  30.    
  31.     XOR %r12, %r12
  32.     XOR %r8, %r8
  33.     MOV %r12, %r8 #pointer for rax
  34. mainLoop:
  35.     CMPB $0, (%rdi)
  36.     JE afterLoop
  37.     CMPB $'0', (%rdi)
  38.     JL noOperation
  39.     CMPB $'9', (%rdi)
  40.     JG noOperation
  41.     CMP $1, %rdx
  42.     JE deleteNumber
  43.     CMP $2, %rdx
  44.     JE transposition
  45.     CMP $3, %rdx
  46.     JE substitute
  47.     JMP noOperation
  48. afterLoop:
  49.     MOV (%rdi), %r9
  50.     MOV %r9, (%r8)
  51.     MOV %r12, %rax
  52.     POP %rsi
  53.     POP %rdi
  54.     POP %rbx
  55.     RET
  56.  
  57. changeMask:
  58.     MOVL $1, mask(, %rbx, 4)
  59.     JMP maskChanged
  60.  
  61. noOperation:
  62.     XOR %r9, %r9
  63.     MOVB (%rdi), %r9b
  64.     MOVB %r9b, (%r8)
  65.     INC %rdi
  66.     INC %r8
  67.     JMP mainLoop
  68.  
  69. deleteNumber:
  70.     XOR %r10, %r10
  71.     MOV (%rdi), %r10
  72.     SUB $'0', %r10
  73.     CMP $0, mask(,%r10d,4)
  74.     JE noOperation
  75.     INC %rdi
  76.     JMP mainLoop
  77.  
  78. transposition:
  79.     XOR %r10, %r10
  80.     MOV (%rdi), %r10
  81.     SUB $'0', %r10
  82.     CMP $0, mask(,%r10d,4)
  83.     JE noOperation
  84.     MOV $9, %r11
  85.     SUB %r10, %r11
  86.     MOV %r11b, (%r8)
  87.     INC %rdi
  88.     INC %r8
  89.     JMP mainLoop
  90.  
  91. substitute:
  92.     MOV (%rdi), %r10
  93.     SUB $'0', %r10
  94.     CMP $0, mask(,%r10d,4)
  95.     JE noOperation
  96.     MOVB %cl, (%rdi)
  97.     INC %rdi
  98.     INC %r8
  99.     JMP mainLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement