mini-libc-mes.M1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ## Copyright (C) 2017 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 is free software: you can redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## stage0 is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. :_start
  17. PUSH_ebp
  18. MOVE_esp_To_ebp
  19. SUB_Immediate8_From_esp !64
  20. CALLI32 %main
  21. ADD_Immediate8_To_esp !0
  22. STORE_eax_To_ebp_offset8 !-4
  23. # exit(r);
  24. PUSH_ebp_offset8 !-4
  25. CALLI32 %exit
  26. ADD_Immediate8_To_esp !4
  27. TEST_eax_eax
  28. LEAVE
  29. RETURN
  30. :_env
  31. PUSH_ebp
  32. MOVE_esp_To_ebp
  33. SUB_Immediate8_From_esp !64
  34. LOAD_eax_From_ebp_offset8 !8
  35. LEAVE
  36. RETURN
  37. :exit
  38. PUSH_ebp
  39. MOVE_esp_To_ebp
  40. SUB_Immediate8_From_esp !64
  41. LOAD_ebx_From_ebp_offset8 !8
  42. LOADI32_eax %1
  43. INT_80
  44. LEAVE
  45. RETURN
  46. :write
  47. PUSH_ebp
  48. MOVE_esp_To_ebp
  49. SUB_Immediate8_From_esp !64
  50. LOAD_ebx_From_ebp_offset8 !8
  51. LOAD_ecx_From_ebp_offset8 !12
  52. LOAD_edx_From_ebp_offset8 !16
  53. LOADI32_eax %4
  54. INT_80
  55. LEAVE
  56. RETURN
  57. :strlen
  58. # while (s[i]) ...
  59. PUSH_ebp
  60. MOVE_esp_To_ebp
  61. SUB_Immediate8_From_esp !64
  62. STORE_To_ebp_offset8_Immediate32 !-4 %0
  63. JUMP32 %strlen_1
  64. :strlen_0
  65. LOAD_eax_From_ebp_offset8 !-4
  66. ADD_To_ebp_offset8_Immediate8 !-4 !1
  67. TEST_eax_eax
  68. :strlen_1
  69. LOAD_eax_From_ebp_offset8 !-4
  70. COPY_edx_To_eax
  71. LOAD_edx_From_ebp_offset8 !8
  72. ADD_eax_To_edx
  73. LOAD8_eax_From_eax_pointer
  74. TEST_eax_eax
  75. TEST_eax_eax
  76. TEST_al_al
  77. JZ8 !strlen_2
  78. JUMP32 %strlen_0
  79. :strlen_2
  80. LOAD_eax_From_ebp_offset8 !-4
  81. LEAVE
  82. RETURN
  83. :eputs
  84. PUSH_ebp
  85. MOVE_esp_To_ebp
  86. SUB_Immediate8_From_esp !64
  87. PUSH_ebp_offset8 !8
  88. CALLI32 %strlen
  89. ADD_Immediate8_To_esp !4
  90. STORE_eax_To_ebp_offset8 !-4
  91. # write(2, s, i);
  92. PUSH_ebp_offset8 !-4
  93. PUSH_ebp_offset8 !8
  94. LOADI32_eax %2
  95. PUSH_eax
  96. CALLI32 %write
  97. ADD_Immediate8_To_esp !12
  98. TEST_eax_eax
  99. LOADI32_eax %0
  100. LEAVE
  101. RETURN
  102. #.data
  103. :g_stdin
  104. '00 00 00 00'
  105. :g_environment
  106. '00 00 00 00'