Advertisement
Coriic

Untitled

Jun 25th, 2017
128
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,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 %r8, %r8
  32.     MOV %rdi, %rax
  33.     MOV %rdi, %r8
  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.     POP %rsi
  52.     POP %rdi
  53.     POP %rbx
  54.     RET
  55.  
  56. changeMask:
  57.     MOVL $1, mask(, %rbx, 4)
  58.     JMP maskChanged
  59.  
  60. noOperation:
  61.     XOR %r10, %r10
  62.     MOVB (%rdi), %r10b
  63.     MOVB %r10b, (%r8)
  64.     INC %rdi
  65.     INC %r8
  66.     JMP mainLoop
  67.  
  68. deleteNumber:
  69.     XOR %r10, %r10
  70.     MOVB (%rdi), %r10b
  71.     SUBB $'0', %r10b
  72.     CMP $0, mask(,%r10d,4)
  73.     JE noOperation
  74.     INC %rdi
  75.     JMP mainLoop
  76.  
  77. transposition:
  78.     XOR %r10, %r10
  79.     MOVB (%rdi), %r10b
  80.     SUBB $'0', %r10b
  81.     CMP $0, mask(,%r10d,4)
  82.     JE noOperation
  83.     MOV $9, %r11
  84.     SUB %r10, %r11
  85.     ADD $'0', %r11
  86.     MOVB %r11b, (%r8)
  87.     INC %rdi
  88.     INC %r8
  89.     JMP mainLoop
  90.  
  91. substitute:
  92.     XOR %r10, %r10
  93.     MOVB (%rdi), %r10b
  94.     SUBB $'0', %r10b
  95.     CMP $0, mask(,%r10d,4)
  96.     JE noOperation
  97.     MOVB %cl, (%r8)
  98.     INC %rdi
  99.     INC %r8
  100.     JMP mainLoop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement