fork download
  1. format ELF64
  2. public _start
  3.  
  4.  
  5. section '.bss' writable
  6. bss_char rb 1
  7.  
  8. section '.text' executable
  9. _start:
  10. mov rax, 571
  11. call print_number
  12. ; call print_line
  13. call exit
  14.  
  15. ; rax | rdx
  16. ; 571/10 = 57 | 1
  17. ; 57/10 5 | 7
  18. ; 5/10 = 0 | 5
  19. ;
  20.  
  21. section '.print_number' executable
  22. ; | input
  23. ; rax => number
  24. print_number:
  25. push rax
  26. push rbx
  27. push rcx
  28. push rdx
  29. xor rcx, rcx
  30. .next_iter:
  31. cmp rax, 0
  32. je .print_iter
  33. mov rbx, 10
  34. xor rdx, rdx
  35. div rbx ; rax/rbx
  36. add rdx, '0' ; результат деления занесён в rdx и к нему прибавляем символ '0'
  37. push rdx
  38. inc rcx
  39. jmp .next_iter
  40. .print_iter:
  41. cmp rcx, 0
  42. je .close
  43. pop rax
  44. call print_char
  45. dec rcx
  46. jmp .print_iter
  47. .close:
  48. pop rdx
  49. pop rcx
  50. pop rbx
  51. pop rax
  52. ret
  53.  
  54. section '.print_char' executable
  55. print_char:
  56. push rax
  57. push rbx
  58. push rcx
  59. push rdx
  60. ; rax = 32|eax = 16|ax = ah|al
  61. mov [bss_char], al
  62. mov rax, 4
  63. mov rbx, 1
  64. mov rcx, bss_char
  65. mov rdx, 1
  66. int 0x80 ; это команда для 32-хбитной арх-ры,но подходит и для 64-х
  67. pop rdx
  68. pop rbx
  69. pop rcx
  70. pop rax
  71. ret
  72.  
  73. section '.print_line' executable
  74. print_line:
  75. push rax
  76. mov rax, 0xA
  77. call print_char
  78. pop rax
  79. ret
  80.  
  81. section '.exit' executable
  82. mov rax, 1
  83. xor rbx, rbx
  84. int 0x80
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.asm:1: error: parser: instruction expected
prog.asm:2: error: parser: instruction expected
prog.asm:5: warning: Unknown section attribute 'writable' ignored on declaration of section `'.bss''
prog.asm:6: error: parser: instruction expected
prog.asm:8: warning: Unknown section attribute 'executable' ignored on declaration of section `'.text''
prog.asm:21: warning: Unknown section attribute 'executable' ignored on declaration of section `'.print_number''
prog.asm:54: warning: Unknown section attribute 'executable' ignored on declaration of section `'.print_char''
prog.asm:73: warning: Unknown section attribute 'executable' ignored on declaration of section `'.print_line''
prog.asm:81: warning: Unknown section attribute 'executable' ignored on declaration of section `'.exit''
ld: cannot find prog.o: No such file or directory
stdout
Standard output is empty