stack.s (1095B)
1 # Stack manipulation 2 3 verb code RESETDATA 4 mov $stack, SP 5 jmp next 6 7 verb code RESETRETURN 8 mov rspbk, %rsp 9 jmp next 10 11 verb code DUP 12 minstk 1 13 _dup 14 jmp next 15 16 verb forth dup2 "2DUP" 17 do OVER 18 do OVER 19 endword 20 21 verb code drop2 "2DROP" 22 minstk 2 23 _drop2: advance SP 24 mov (SP), TOS 25 advance SP 26 jmp next 27 28 verb code DROP 29 minstk 1 30 _drop: mov (SP), TOS 31 advance SP 32 jmp next 33 34 _uflow: do RESETDATA 35 saycr "\x1B[91m Stack underflow!" 36 do QUIT 37 38 verb code SWAP 39 minstk 2 40 push TOS 41 mov (SP), TOS 42 pop (SP) 43 jmp next 44 45 verb code OVER 46 minstk 2 47 push (SP) 48 _dup 49 pop TOS 50 jmp next 51 52 verb code ROT 53 minstk 3 54 mov (SP), ACC 55 mov TOS, (SP) 56 mov -8(SP), TOS 57 mov ACC, -8(SP) 58 jmp next 59 60 verb code ROLL 61 minstk 1 62 cmp TOS, 0 63 je 1f 64 shl TOS 65 shl TOS 66 shl TOS 67 add SP, TOS 68 mov (TOS), TOS 69 1: jmp next 70 71 verb code DEPTH 72 mov $stack, ACC 73 sub SP, ACC 74 shr ACC 75 shr ACC 76 shr ACC 77 _dup 78 mov ACC, TOS 79 jmp next 80 81 top: codeword 82 push SP 83 _dup 84 pop TOS 85 jmp next 86 87 verb code pushret ">R" 88 minstk 1 89 push TOS 90 jmp _drop 91 92 verb code popret "R>" 93 _dup 94 pop TOS 95 jmp next 96 97 verb code peekret "R@" 98 _dup 99 mov (%rsp), TOS 100 jmp next