Minimal programming language prototype, created with goal to have very small compiler, so that anyone can write his own compiler for it.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

112 строки
3.4KB

  1. linux_read_system_call = 0
  2. linux_write_system_call = 1
  3. linux_open_system_call = 2
  4. linux_close_system_call = 3
  5. linux_exit_system_call = 60
  6. standard_input = 0
  7. standard_output = 1
  8. format ELF64 executable 3
  9. segment readable executable
  10. main:
  11. mov [echo_0], text_data ; text);
  12. call echo ; echo (
  13. loop_1:
  14. cmp [main_x], 51
  15. jnb loop_1e
  16. xor rdx, rdx
  17. mov eax, [main_x]
  18. mov ebx, 15
  19. idiv rbx
  20. cmp edx, 0
  21. jne n3
  22. mov [echo_0], fb
  23. call echo
  24. jmp n0
  25. n3:
  26. xor rdx, rdx
  27. mov eax, [main_x]
  28. mov ebx, 3
  29. idiv rbx
  30. cmp edx, 0
  31. jne n1
  32. mov [echo_0], f
  33. call echo
  34. jmp n0
  35. n1:
  36. xor rdx, rdx
  37. mov eax, [main_x]
  38. mov ebx, 5
  39. idiv rbx
  40. cmp edx, 0
  41. jne n2
  42. mov [echo_0], b
  43. call echo
  44. jmp n0
  45. n2:
  46. mov [echo_0], n
  47. call echo
  48. n0:
  49. inc [main_x]
  50. jmp loop_1
  51. loop_1e:
  52. ;
  53. mov rax, linux_exit_system_call ; <main> return;;
  54. xor rdi, rdi
  55. syscall
  56. ;~string_length (character * text):
  57. ;~natural length = 0;
  58. ;~loop (* (text + length++));
  59. ;~return (length);;
  60. string_length: ; string_length
  61. mov [string_length_length], 0 ; length = 0;
  62. mov rax, [string_length_0] ; text
  63. loop_0: ; loop_0
  64. cmp byte [rax], 0 ; (* (text + length)) != '\0'
  65. je loop_0e
  66. inc rax ; text + length
  67. inc [string_length_length] ; length++
  68. jmp loop_0 ; if not go loop_0
  69. loop_0e:
  70. xor rax, rax
  71. mov eax, [string_length_length] ; return (length);
  72. ret ; ;
  73. ;~echo (character * text):
  74. ;~system (linux_write_system_call, standard_output, text, string_length (text));
  75. ;~return;;
  76. echo: ; echo )
  77. mov rax, [echo_0] ; |
  78. mov [string_length_0], rax ; |
  79. call string_length ; |
  80. mov rdx, rax ; | string_length (text)
  81. mov rsi, [echo_0] ; text
  82. mov rdi, standard_output ; standard_output
  83. mov rax, linux_write_system_call ; linux_write_system_call
  84. syscall ; system (
  85. xor rax, rax ; return;;
  86. ret ;
  87. segment readable writable
  88. ; variable
  89. string_length_length dd 0 ; natural length = 0;
  90. main_x dd 1 ; integer x = 0;
  91. ; function
  92. echo_0 dq 0 ; character * text
  93. string_length_0 dq 0 ; character * text
  94. ; data
  95. text_data db 'Heyo world!', 10, 0
  96. fb db 'fizzbuzz', 10, 0
  97. f db 'fizz', 10, 0
  98. b db 'buzz', 10, 0
  99. n db 'number', 10, 0