Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDB 1.45 KB | None | 0 0
  1. SYSEXIT = 1
  2. SYSREAD = 3
  3. SYSWRITE = 4
  4. STDOUT = 1
  5. SUCCESS_CODE = 0
  6.  
  7. MAX_BYTES = 256
  8. N = 55
  9.  
  10. .bss
  11. .comm prev, 256     #previous element of Fibonacci sequence
  12. .comm curr, 256     #current element of Fibonacci sequence
  13.  
  14. .text
  15. .global _start
  16.  
  17.  
  18. _start:
  19. mov $MAX_BYTES, %eax  # memory register
  20. dec %eax
  21. movb $0, %dh  # first fib number
  22. movb $1, %dl  # second fib number
  23. movb %dh, prev(,%eax,1)  # move numbers to memory
  24. movb %dl, curr(,%eax,1)
  25. mov $1, %ecx  # start from 2 (%ecx will be incremented before 1st loop)
  26. jmp fibonacci
  27.  
  28. fibonacci:
  29. cmp $N, %ecx  # check if Nth element have been found
  30. je exit  # exit
  31. inc %ecx  # else increment the counter and add prev to curr
  32. jmp setup_add
  33.  
  34. setup_add:
  35. mov $MAX_BYTES, %eax  # position counter
  36. mov $0, %ebx  # reset carry
  37. mov $1, %edi  # carry value
  38.  
  39. add_loop:
  40. sub $1, %eax
  41. movb prev(,%eax,1), %dh  # copy previous number to %dh (buffor)
  42. movb curr(,%eax,1), %dl  # copy current number to %dl  (buffor)
  43. movb %dl, prev(,%eax,1)
  44. add  %bl, %dl  # add carry do destination
  45. mov $0, %ebx  # reset carry
  46. cmovc %edi, %ebx  # set carry if flag is set to do so
  47. addb  %dh, %dl  # add previous number to current
  48. cmovc %edi, %ebx  # set carry if flag is set to do so
  49. movb %dl, curr(,%eax,1)  # save results on current position
  50. cmp $0, %eax  # exit if possition = zero
  51. je exit_add
  52. jmp add_loop  # else continue to the next digit
  53.  
  54. exit_add:
  55. jmp fibonacci
  56.  
  57.  
  58. exit:
  59. mov $SYSEXIT, %eax
  60. mov $0, %ebx
  61. int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement