Guest User

Untitled

a guest
Jul 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. %assign STDIN 0
  2. %assign STDOUT 1
  3.  
  4. ; Printing macro
  5. ; 1: Address of the content
  6. ; 2: Length of the content
  7. ; 3: File Descriptor of the output
  8. %macro RFM_PRINT 3
  9. MOV ECX, %1
  10. MOV EDX, %2
  11. MOV EAX, 4
  12. MOV EBX, %3
  13. INT 80H
  14. %endmacro
  15.  
  16. ; Reading macro
  17. ; 1: File Descriptor of the output
  18. ; 2: Pointer to the string
  19. ; 3: MaxSize
  20. %macro RFM_READ 3
  21. mov EAX, 3
  22. mov EBX, %1
  23. mov ECX, %2
  24. mov EDX, %3
  25. INT 80H
  26. %endmacro
  27.  
  28. ; Exit macro
  29. ; 1: Exit Status Code
  30. %macro RFM_EXIT 1
  31. mov EBX, %1
  32. mov EAX, 1
  33. INT 80H
  34. %endmacro
  35.  
  36. SECTION .data
  37. fat: equ 12
  38.  
  39. SECTION .bss
  40. string : resb 5
  41.  
  42. SECTION .text
  43. global _start
  44.  
  45. _start:
  46.  
  47. mov ESI, fat
  48. inc ESI
  49. mov EAX, 1
  50. mov ECX, 1
  51. LOOP_FATORIAL:
  52. cmp ECX, ESI
  53. je END_LOOP_FATORIAL
  54. mul ECX
  55. inc ECX
  56. jmp LOOP_FATORIAL
  57. END_LOOP_FATORIAL:
  58.  
  59. ; EAX tem o fatorial
  60.  
  61. mov ESI, 10
  62. mov ECX, 0 ; ECX contém o tamanho do número
  63.  
  64. NUMBER_TO_STRING:
  65. cmp EAX, 0
  66. je END_NUMBER_TO_STRING
  67. inc ECX
  68. mov EDX, 0
  69. div ESI
  70. add EDX, 48
  71. push EDX
  72. jmp NUMBER_TO_STRING
  73. END_NUMBER_TO_STRING:
  74.  
  75. cmp ECX, 0
  76. jne IF_NOT_ZERO
  77. inc ECX
  78. IF_NOT_ZERO:
  79.  
  80. mov ESI, ECX
  81.  
  82. PRINT_STRING_NUMBER:
  83. cmp ESI, 0
  84. je END_PRINT_STRING_NUMBER
  85. dec ESI
  86. pop EDX
  87. mov [string], byte DL
  88. RFM_PRINT string, 1, STDOUT
  89. jmp PRINT_STRING_NUMBER
  90. END_PRINT_STRING_NUMBER:
  91.  
  92. RFM_EXIT 0
Add Comment
Please, Sign In to add comment