mini-libc-mes.hex2 1.9 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. ## stage0's hex2 format for x86
  17. ## !<label> 1 byte relative
  18. ## $<label> 2 byte address
  19. ## @<label> 2 byte relative
  20. ## %<label> 4 byte relative
  21. ## &<label> 4 byte address
  22. ## label_<label> function-local
  23. ## string_<count> string
  24. ##
  25. #.text
  26. :_start
  27. 55 89 e5 83 ec 40
  28. e8 %main 83 c4 00
  29. 89 45 fc
  30. # exit(r);
  31. ff 75 fc
  32. e8 %exit 83 c4 04
  33. 85 c0
  34. c9 c3
  35. :_env
  36. 55 89 e5 83 ec 40
  37. 8b 45 08
  38. c9 c3
  39. :exit
  40. 55 89 e5 83 ec 40
  41. # asm(".byte 0x8b 0x5d 0x08");
  42. 8b 5d 08
  43. # asm(".byte 0xb8 0x01 0x00 0x00 0x00");
  44. b8 01 00 00 00
  45. # asm(".byte 0xcd 0x80");
  46. cd 80
  47. c9 c3
  48. :write
  49. 55 89 e5 83 ec 40
  50. # asm(".byte 0x8b 0x5d 0x08");
  51. 8b 5d 08
  52. # asm(".byte 0x8b 0x4d 0x0c");
  53. 8b 4d 0c
  54. # asm(".byte 0x8b 0x55 0x10");
  55. 8b 55 10
  56. # asm(".byte 0xb8 0x04 0x00 0x00 0x00");
  57. b8 04 00 00 00
  58. # asm(".byte 0xcd 0x80");
  59. cd 80
  60. c9 c3
  61. :strlen
  62. # while (s[i]) ...
  63. 55 89 e5 83 ec 40
  64. c7 45 fc 00 00 00 00
  65. e9 09 00 00 00
  66. 8b 45 fc
  67. 83 45 fc 01
  68. 85 c0
  69. 8b 45 fc
  70. 89 c2
  71. 8b 55 08
  72. 01 d0
  73. 0f b6 00
  74. 85 c0
  75. 85 c0
  76. 84 c0 74 05
  77. e9 dd ff ff ff
  78. 8b 45 fc
  79. c9 c3
  80. :eputs
  81. 55 89 e5 83 ec 40
  82. ff 75 08
  83. e8 %strlen 83 c4 04
  84. 89 45 fc
  85. # write(2, s, i);
  86. ff 75 fc
  87. ff 75 08
  88. b8 02 00 00 00
  89. 50
  90. e8 %write 83 c4 0c
  91. 85 c0
  92. b8 00 00 00 00
  93. c9 c3
  94. #.data
  95. :g_stdin
  96. 00 00 00 00
  97. :g_environment
  98. 00 00 00 00