Linux x86_64 implementation of libglitch : https://github.com/erlehmann/libglitch.git
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yaglitch_op.asm 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. OP:
  2. .numeric:
  3. ; rdi contain the number
  4. shr rdi, 32
  5. ._push:
  6. ; push rdi (edi) on stack_buff
  7. mov eax, edi
  8. xor rbx, rbx
  9. mov ebx, [tosp]
  10. add ebx, 4
  11. cmp ebx, STACK_SZ * 4
  12. jl .go_push
  13. mov ebx, 0
  14. .go_push:
  15. mov [tosp], ebx
  16. lea rdi, [stack_buff+rbx]
  17. stosd
  18. ret
  19. .drop: ; drop just calls pop
  20. ._pop:
  21. ; pop eax from stack_buff
  22. xor rbx, rbx
  23. mov ebx, [tosp]
  24. lea rsi, [stack_buff+rbx]
  25. xor rax, rax
  26. lodsd
  27. test ebx, ebx
  28. jz .pop_no_dec
  29. sub ebx, 4
  30. jmp .pop_end
  31. .pop_no_dec:
  32. mov ebx, (STACK_SZ-1) * 4
  33. .pop_end:
  34. mov [tosp], ebx
  35. ret
  36. .t: ; push t on the stack
  37. mov edi, [t]
  38. call ._push
  39. ret
  40. .put:
  41. pushf
  42. cld
  43. xor rbx, rbx
  44. xor rax, rax
  45. mov ebx, [tosp]
  46. lea rsi, [stack_buff+rbx]
  47. lodsd
  48. and eax, 0xFF
  49. inc eax
  50. mov edx, eax
  51. lodsd
  52. neg rdx
  53. lea rdi, [stack_buff + rdx]
  54. stosq
  55. call OP._pop
  56. popf
  57. ret
  58. .mul:
  59. call .prep_2arg
  60. mul ebx
  61. mov edi, eax
  62. call OP._push
  63. ret
  64. .div:
  65. call .prep_2arg
  66. test ebx, ebx
  67. jz .nodiv
  68. xor rdx, rdx
  69. div ebx
  70. jmp .divend
  71. .nodiv:
  72. xor eax, eax
  73. .divend:
  74. mov edi, eax
  75. call OP._push
  76. ret
  77. .add:
  78. call .prep_2arg
  79. add eax, ebx
  80. mov edi, eax
  81. call OP._push
  82. ret
  83. .sub:
  84. call .prep_2arg
  85. sub eax, ebx
  86. mov edi, eax
  87. call OP._push
  88. ret
  89. .mod:
  90. call .prep_2arg
  91. test rbx, rbx
  92. jz .nomod
  93. xor edx, edx
  94. div ebx
  95. jmp .endmod
  96. .nomod:
  97. xor edx, edx
  98. .endmod:
  99. mov edi, edx
  100. call OP._push
  101. ret
  102. .lshift:
  103. call OP._pop
  104. push rax
  105. call OP._pop
  106. pop rcx
  107. shl eax, cl
  108. mov edi, eax
  109. call OP._push
  110. ret
  111. .rshift:
  112. call OP._pop
  113. push rax
  114. call OP._pop
  115. pop rcx
  116. shr eax, cl
  117. mov edi, eax
  118. call OP._push
  119. ret
  120. .and:
  121. call .prep_2arg
  122. and eax, ebx
  123. mov edi, eax
  124. call OP._push
  125. ret
  126. .or:
  127. call .prep_2arg
  128. or eax, ebx
  129. mov edi, eax
  130. call OP._push
  131. ret
  132. .xor:
  133. call .prep_2arg
  134. xor eax, ebx
  135. mov edi, eax
  136. call OP._push
  137. ret
  138. .not:
  139. call OP._pop
  140. not eax
  141. mov edi, eax
  142. call OP._push
  143. ret
  144. .dup:
  145. call OP._pop
  146. push rax
  147. mov edi, eax
  148. call OP._push
  149. pop rdi
  150. call OP._push
  151. ret
  152. .pick:
  153. call OP._pop
  154. inc eax
  155. and eax, 0xFF
  156. mov ebx, 4
  157. mov ecx, [tosp]
  158. mul ebx ; mul by data size
  159. cmp eax, [tosp]
  160. jg .pick_loop
  161. sub ecx, eax
  162. jmp .pick_lea
  163. .pick_loop: ; eax > tosp
  164. sub eax, ecx
  165. mov ecx, (STACK_SZ - 1) * 4
  166. sub ecx, eax
  167. .pick_lea:
  168. lea rsi, [stack_buff+ecx]
  169. lodsd
  170. push rax
  171. call OP._pop
  172. pop rdi
  173. call OP._push
  174. ret
  175. .swap:
  176. call OP._pop
  177. push rax
  178. call OP._pop
  179. xchg rax, [rsp]
  180. mov edi, eax
  181. call OP._push
  182. pop rdi
  183. call OP._push
  184. ret
  185. .lt:
  186. call .prep_2arg
  187. xor rdi, rdi
  188. cmp eax, ebx
  189. jge .lt_false
  190. not rdi
  191. .lt_false:
  192. call OP._push
  193. ret
  194. .gt:
  195. call .prep_2arg
  196. xor rdi, rdi
  197. cmp eax, ebx
  198. jle .gt_false
  199. not rdi
  200. .gt_false:
  201. call OP._push
  202. ret
  203. .eq:
  204. call .prep_2arg
  205. xor rdi, rdi
  206. cmp eax, ebx
  207. jne .eq_false
  208. not rdi
  209. .eq_false:
  210. call OP._push
  211. ret
  212. .prep_2arg:
  213. ; utils that pop both arguments V1 in eax, V2 in ebx
  214. call OP._pop
  215. push rax
  216. call OP._pop
  217. pop rbx
  218. ret