Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. STDIN = 0
  2. STDOUT = 1
  3. SYS_EXIT = 1
  4. SYS_WRITE = 4
  5. SYS_READ = 3
  6. EXIT_SUCCESS = 0
  7.  
  8. .data
  9. text: .space 10,0
  10. text_len: .long .-text
  11.  
  12. .text
  13. .global _start
  14. _start:
  15.  
  16. movl $SYS_READ, %eax
  17. movl $STDIN, %ebx
  18. movl $text, %ecx
  19. movl text_len, %edx
  20. int $0x80
  21.  
  22. movl $0, %edi # iterator
  23. movq %rax, %r8 # ilosc znakow z stdin
  24.  
  25. ###### movq $0, %rax
  26. dec %r8
  27.  
  28. main_loop:
  29.  
  30. movl $0, %ebx # zerowanie tmp
  31.  
  32. movb text(, %edi, 1), %bl #znak z bufora do tmp
  33.  
  34. subb $0x30, %bl #ASCII -> hex (dla 0-9)
  35.  
  36. cmp $9, %ebx # jesli dalej > 9 (czyli znaki A-Z)
  37. jl next
  38. subb $0x07, %bl
  39.  
  40. next:
  41.  
  42. addq %rbx, %r9 # r9 - "akumulator"
  43. shlq $4, %r9
  44.  
  45. inc %edi #nastepna pozycja
  46. cmp %r8d, %edi
  47. jl main_loop
  48.  
  49. end:
  50.  
  51. shrq $4, %r9
  52.  
  53. mov $SYS_EXIT, %eax
  54. mov $EXIT_SUCCESS, %ebx
  55. int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement