Minimal programming language prototype, created with goal to have very small compiler, so that anyone can write his own compiler for it.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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