123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- OP:
- .numeric:
- ; rdi contain the number
- shr rdi, 32
- ._push:
- ; push rdi (edi) on stack_buff
- mov eax, edi
- xor rbx, rbx
- mov ebx, [tosp]
- add ebx, 4
- cmp ebx, STACK_SZ * 4
- jl .go_push
- mov ebx, 0
- .go_push:
- mov [tosp], ebx
- lea rdi, [stack_buff+rbx]
- stosd
- ret
-
- .drop: ; drop just calls pop
- ._pop:
- ; pop eax from stack_buff
- xor rbx, rbx
- mov ebx, [tosp]
- lea rsi, [stack_buff+rbx]
- xor rax, rax
- lodsd
- test ebx, ebx
- jz .pop_no_dec
- sub ebx, 4
- jmp .pop_end
- .pop_no_dec:
- mov ebx, (STACK_SZ-1) * 4
- .pop_end:
- mov [tosp], ebx
- ret
-
-
- .t: ; push t on the stack
- mov edi, [t]
- call ._push
- ret
-
- .put:
- pushf
- cld
- xor rbx, rbx
- xor rax, rax
- mov ebx, [tosp]
- lea rsi, [stack_buff+rbx]
- lodsd
- and eax, 0xFF
- inc eax
- mov edx, eax
- lodsd
- neg rdx
- lea rdi, [stack_buff + rdx]
- stosq
- call OP._pop
- popf
- ret
- .mul:
- call .prep_2arg
- mul ebx
- mov edi, eax
- call OP._push
- ret
- .div:
- call .prep_2arg
- test ebx, ebx
- jz .nodiv
- xor rdx, rdx
- div ebx
- jmp .divend
- .nodiv:
- xor eax, eax
- .divend:
- mov edi, eax
- call OP._push
- ret
- .add:
- call .prep_2arg
- add eax, ebx
- mov edi, eax
- call OP._push
- ret
- .sub:
- call .prep_2arg
- sub eax, ebx
- mov edi, eax
- call OP._push
- ret
- .mod:
- call .prep_2arg
- test rbx, rbx
- jz .nomod
- xor edx, edx
- div ebx
- jmp .endmod
- .nomod:
- xor edx, edx
- .endmod:
- mov edi, edx
- call OP._push
- ret
- .lshift:
- call OP._pop
- push rax
- call OP._pop
- pop rcx
- shl eax, cl
- mov edi, eax
- call OP._push
- ret
- .rshift:
- call OP._pop
- push rax
- call OP._pop
- pop rcx
- shr eax, cl
- mov edi, eax
- call OP._push
- ret
- .and:
- call .prep_2arg
- and eax, ebx
- mov edi, eax
- call OP._push
- ret
- .or:
- call .prep_2arg
- or eax, ebx
- mov edi, eax
- call OP._push
- ret
- .xor:
- call .prep_2arg
- xor eax, ebx
- mov edi, eax
- call OP._push
- ret
- .not:
- call OP._pop
- not eax
- mov edi, eax
- call OP._push
- ret
- .dup:
- call OP._pop
- push rax
- mov edi, eax
- call OP._push
- pop rdi
- call OP._push
- ret
- .pick:
- call OP._pop
- inc eax
- and eax, 0xFF
- mov ebx, 4
- mov ecx, [tosp]
- mul ebx ; mul by data size
- cmp eax, [tosp]
- jg .pick_loop
- sub ecx, eax
- jmp .pick_lea
- .pick_loop: ; eax > tosp
- sub eax, ecx
- mov ecx, (STACK_SZ - 1) * 4
- sub ecx, eax
- .pick_lea:
- lea rsi, [stack_buff+ecx]
- lodsd
- push rax
- call OP._pop
- pop rdi
- call OP._push
- ret
-
-
- .swap:
- call OP._pop
- push rax
- call OP._pop
- xchg rax, [rsp]
- mov edi, eax
- call OP._push
- pop rdi
- call OP._push
- ret
- .lt:
- call .prep_2arg
- xor rdi, rdi
- cmp eax, ebx
- jge .lt_false
- not rdi
- .lt_false:
- call OP._push
- ret
- .gt:
- call .prep_2arg
- xor rdi, rdi
- cmp eax, ebx
- jle .gt_false
- not rdi
- .gt_false:
- call OP._push
- ret
- .eq:
- call .prep_2arg
- xor rdi, rdi
- cmp eax, ebx
- jne .eq_false
- not rdi
- .eq_false:
- call OP._push
- ret
-
- .prep_2arg:
- ; utils that pop both arguments V1 in eax, V2 in ebx
- call OP._pop
- push rax
- call OP._pop
- pop rbx
- ret
|