-
Notifications
You must be signed in to change notification settings - Fork 0
/
cantilever.S
1971 lines (1743 loc) · 37.1 KB
/
cantilever.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <asm/unistd.h>
// #include <bits/socket.h>
#include <asm/mman.h>
// #include "inc/sys_defs.h"
# Warnings: be very careful about using push
# and pop in non-Forth functions -- there's a
# return address on top of the stack!
# Useful values ######################################
.set HEAP_SIZE, 128*1024*1024 # 128 meg
.set SCRATCH_SIZE, 16*1024 # 16k
.set BUFFER_SIZE, 16*1024 # 4k
.set WORD_BUFFER_SIZE, 256
.set FLAG_TABLE_SIZE, (127-32) # non-space ASCII chars
.set CELL_BITS, 2
.set CELL_SIZE, (1<<CELL_BITS)
.set DS_SIZE, (64*CELL_SIZE)
.set link, 0
.set BASE_4_YEAR, 1461
.set LILIAN_CORRECTION, 6345
// #define CANTILEVER_COMPILATION_TRACE
//#define CANTILEVER_EXECUTION_TRACE
// #define CANTILEVER_STACK_TRACE
// #define CANTILEVER_CHEAP_DATE
#ifdef CANTILEVER_EXECUTION_TRACE
#define TRACE_CODE call _trace
#else
#define TRACE_CODE
#endif
######################################################
# macros #
######################################################
#define JUMP(tgt) (tgt - .)
#define DATA .int
#define ToS %ebx
# Structural macros ##################################
.set LFA_OFFS, (1*CELL_SIZE)
.set BFA_OFFS, (2*CELL_SIZE)
.set CFA_OFFS, (3*CELL_SIZE)
.set PFA_OFFS, (4*CELL_SIZE)
.macro header label, name, behav
.section .data
.align CELL_SIZE, 0
dict_label_\label:
DATA (100001f - 100000f - 1)
100000:
.ifeqs "\name", ""
.asciz "\label"
.else
.asciz "\name"
.endif
100001:
.align CELL_SIZE, 0
dict_\label:
DATA link
DATA dict_label_\label
DATA \behav
.set link, dict_\label
.endm
.macro prim label, name, behav=storeinc
header \label, "\name", \behav
\label:
DATA prim_\label
.section .text
.align CELL_SIZE
prim_\label:
TRACE_CODE
.endm
.macro word label, name, behav=storeinc, handler=do
header \label, "\name", \behav
\label:
DATA \handler
word_\label:
.endm
.macro constant label, val, name
word \label, "\name", , doconst
# push $\val
# next
DATA \val
.endm
.macro variable label, val=0, name
word \label, "\name", , dovar
var_\label:
DATA \val
.endm
.macro string label, str, name
constant \label, str_\label, "\name"
.section .data
str_\label:
DATA (20001f - str_text_\label - 1)
str_text_\label:
.asciz "\str"
20001:
.align CELL_SIZE, 0
.endm
# Code macros ########################################
.macro next
mov (%esi), %eax
add $CELL_SIZE, %esi
jmp *(%eax)
.align CELL_SIZE
.endm
.macro end
DATA endcol
.endm
.macro string_len_in_cells reg
shr $CELL_BITS, \reg
inc \reg
.endm
.macro pushrs reg
lea -CELL_SIZE(%ebp), %ebp
movl \reg, (%ebp)
.endm
.macro poprs, reg
mov (%ebp), \reg
lea CELL_SIZE(%ebp), %ebp
.endm
.macro align_dp
add $(CELL_SIZE-1), %edi
and $0xfffffffc, %edi
.endm
.macro times_ten reg
shl $1, \reg
lea (\reg, \reg, 4), \reg
.endm
.macro times_60 reg
shl $2, \reg
lea (\reg, \reg, 4), \reg
lea (\reg, \reg, 2), \reg
.endm
.macro digit from, to, err
movb \from, \to
sub $'0', \to
cmp $9, \to
ja \err
.endm
######################################################
# C-style functions #
######################################################
# Initialisation #####################################
.section .data
constant HeapBaseAddr . "heap-base-addr"
.section .text
.globl _start
.align CELL_SIZE
_start:
cld
mov (%esp), %eax
mov %eax, var_argc
lea CELL_SIZE(%esp), %eax
mov %eax, var_argv
mov %eax, var_argv0
mov $0xd50d50, ToS
mov %esp, var_ds0
mov %esp, %ebp
sub $DS_SIZE, %ebp
mov %ebp, var_rs0
mov $cold_start, %esi
next
# Utility function ###################################
.align CELL_SIZE
_fill_buffer:
# ToS has been preserved before we were called
mov $__NR_read, %eax
mov var_inChannel, ToS
mov var_ioBuffer, %ecx
mov %ecx, var_bufpos // reset buffer position
mov $BUFFER_SIZE, %edx
int $0x80
test %eax, %eax
jbe _eof
add %eax, %ecx
mov %ecx, var_bufend
// fallthrough
.align CELL_SIZE
_key: # leaves result on ToS
mov var_bufpos, %edx
cmp var_bufend, %edx
jae _fill_buffer
movzbl (%edx), ToS
inc %edx
mov %edx, var_bufpos
ret
.align CELL_SIZE
_eof:
mov var_ioBuffer, %eax
mov %eax, var_bufend
mov %eax, var_bufpos
pop %eax # _key return addr (we're using regular CPU call-ret)
pop %eax # _word return addr
pop %eax # the function that called _key or _word had already pushed ToS
mov $_eof_wrap, %esi
next
#ifdef CANTILEVER_EXECUTION_TRACE
_space_buffer:
.space 128, ' '
.align CELL_SIZE
_trace:
# print spaces based on return stack depth
push %eax
mov var_rs0, %edx
mov $2, ToS
mov $__NR_write, %eax
mov $_space_buffer, %ecx
sub %ebp, %edx
int $0x80
# print function name
mov (%esp), %eax
mov (LFA_OFFS-CFA_OFFS)(%eax), %ecx
mov (%ecx), %edx
add $CELL_SIZE, %ecx
mov $__NR_write, %eax
int $0x80
# print return char
mov $__NR_write, %eax
push $10
mov %esp, %ecx
mov $1, %edx
int $0x80
pop %ecx
pop %eax
ret
#endif
.align CELL_SIZE
_word: // copy the next word into wordbuffer
// skip whitespace
call _key
cmpb $' ', %bl
jbe _word
// copy word
mov $wordbuffer_text, %edx
1:
movb %bl, (%edx)
inc %edx
cmpl $end_wordbuffer, %edx
jae 2f // buffer overflow!
pushrs %edx // save our pointer
call _key
poprs %edx // ...and restore it
cmpb $' ', %bl
ja 1b
movl $0, CELL_SIZE(%edx) // add two words of nulls after word
//mov $0, 8(%edx)
// populate the length field of the buffer
movl $0, (%edx)
sub $wordbuffer_text, %edx
mov %edx, wordbuffer
ret
2: # TODO: THIS MAY BE BORKED!
// TODO: should skip the rest of the long word too...
movl $0x202e2e2e, wordbuffer+12 // truncate the long word with "... "
movl $12, wordbuffer
movl $wordbuffer, (%ebp) // over-write our return address
push $str_TooLong
# handle error. Was function, but used only here
mov $_error_wrap, %esi
next
# Wrappers for calling words from code ###############
.align CELL_SIZE
cold_start:
DATA initialiseVM
.align CELL_SIZE
_error_wrap:
DATA lit, 2, error
.align CELL_SIZE
_eof_wrap:
DATA EndOfFile, raise, tailcall, reset
######################################################
# Forth-style code words #
######################################################
# codewords ##########################################
.align CELL_SIZE
do:
TRACE_CODE
pushrs %esi // save return address
lea CELL_SIZE(%eax), %esi
next
.align CELL_SIZE
doconst:
push ToS
mov CELL_SIZE(%eax), ToS
TRACE_CODE
next
.align CELL_SIZE
dovar:
push ToS
lea CELL_SIZE(%eax), ToS
TRACE_CODE
next
# The black-magic of forth: data with behaviour.
#
# ... | dodoes | behav | data ...
#
# A more typical implementation would have been:
#
# ... | dodoes | ptr | data ... | behav
# \______________7
#
# but we remove the indirection as we have anonymous functions
#
.align CELL_SIZE
dodoes:
push ToS
pushrs %esi
lea (2*CELL_SIZE)(%eax), ToS
mov CELL_SIZE(%eax), %esi
next
# System calls #######################################
# System call numbers
constant SysExit, __NR_exit
constant SysRead, __NR_read
constant SysWrite, __NR_write
constant SysOpen, __NR_open
constant SysClose, __NR_close
constant SysStat, __NR_fstat
constant SysMmap, __NR_mmap
constant SysMunmap, __NR_munmap
constant SysBrk, __NR_brk
constant SysIOCtl, __NR_ioctl
constant SysTime, __NR_time
constant SysNanosleep, __NR_nanosleep
# prims
prim syscall0 # id -- result
mov ToS, %eax
int $0x80
mov %eax, ToS
next
prim syscall1 # arg id -- result
mov ToS, %eax
pop ToS
int $0x80
mov %eax, ToS
next
prim syscall2 # arg2 arg1 id -- result
mov ToS, %eax
pop ToS
pop %ecx
int $0x80
mov %eax, ToS
next
prim syscall3 # arg3 arg2 arg1 id -- result
mov ToS, %eax
pop ToS
pop %ecx
pop %edx
int $0x80
mov %eax, ToS
next
prim syscall6 # arg6 arg5 ... arg1 id -- result
# This is slightly different because for >5 args
# Linux expects args to be passed by pointer.
# In this case we simply use the stack
mov ToS, %eax
mov %esp, ToS
int $0x80
add $(6*CELL_SIZE), %esp
mov %eax, ToS
next
# IO prims ###########################################
# basic IO
constant stdin, 0
constant stdout, 1
constant stderr, 2
variable inChannel, 0, "in-channel"
variable outChannel, 1, "out-channel"
variable errChannel, 2, "err-channel"
# NOTE: values are octal!
constant ReadOnly, 0
constant WriteOnly, 01101
constant ReadWrite, 02202
prim key # -- c
push ToS
call _key
next
prim word # -- str
push ToS
call _word
// push the address of temporary buffer
mov $wordbuffer, ToS
next
# Logical and bitwise prims ##########################
constant true, -1
constant false, 0
prim match "matches?" # n1 n2 -- n1 bool
# semi-destructive equals for pattern matching
xor %eax, %eax
cmpl (%esp), ToS
setne %al
dec %eax
mov %eax, ToS
next
prim between "btw?" # n lower upper -- bool
pop %ecx # lower
pop %eax # n
sub %ecx, ToS # upper-lower
sub %ecx, %eax # n-lower
xor %ecx, %ecx
cmp ToS, %eax
seta %cl
dec %ecx
mov %ecx, ToS
next
prim eq, "=" // a b -- bool
pop %eax
xor %ecx, %ecx
cmpl %eax, ToS
setne %cl
dec %ecx
mov %ecx, ToS
next
prim neq, "<>" // a b -- bool
pop %eax
xor %ecx, %ecx
cmpl %eax, ToS
sete %cl
dec %ecx
mov %ecx, ToS
next
prim ge, ">="
pop %edx
xor %ecx, %ecx
cmpl ToS, %edx
setl %cl
dec %ecx
mov %ecx, ToS
next
prim gt, ">"
pop %edx
xor %ecx, %ecx
cmpl ToS, %edx
setle %cl
dec %ecx
mov %ecx, ToS
next
prim le, "<="
pop %edx
xor %ecx, %ecx
cmpl ToS, %edx
setg %cl
dec %ecx
mov %ecx, ToS
next
prim lt, "<"
pop %eax
xor %ecx, %ecx
cmpl ToS, %eax
setge %cl
dec %ecx
mov %ecx, ToS
next
prim and
pop %eax
and %eax, ToS
next
prim or
pop %eax
or %eax, ToS
next
prim xor
pop %eax
xor %eax, ToS
next
prim not
not ToS
next
prim bool
xor %eax, %eax
test ToS, ToS
setz %al
dec %eax
mov %eax, ToS
next
prim lshift, "shift-up" // int n -- int
mov ToS, %ecx
pop ToS
shl %cl, ToS
next
prim rshift, "shift-down" // int n -- int
mov ToS, %ecx
pop ToS
sar %cl, ToS
next
# Arithmetic prims ###################################
constant zero, 0, "0"
constant one, 1, "1"
constant minus_one, -1 "-1"
prim mul, "*" // int int -- int
pop %eax
imull ToS
mov %eax, ToS
// TODO: check for overflow
next
prim mulDiv, "*/" // int int int -- int
mov ToS, %ecx
pop %eax
imull (%esp)
idiv %ecx
mov %eax, ToS
next
prim udivmod, "/modu" # int int -- int int
pop %eax
xor %edx, %edx
divl ToS
mov %edx, ToS
push %eax
next
prim divmod "/mod" # int int -- int int
pop %eax
cdq // sign-extend %eax into %edx
idivl ToS
mov %edx, ToS
push %eax
next
prim sub, "-" // int int -- int
pop %eax
sub ToS, %eax
mov %eax, ToS
next
prim add, "+" // int int -- int
pop %eax
add %eax, ToS
next
prim neg
negl ToS
next
prim inc, "1+"
incl ToS
next
prim dec, "1-"
decl ToS
next
prim double, "2*"
shl $1, ToS
next
prim min // int int -- int
pop %eax
cmpl %eax, ToS
jl 1f
mov %eax, ToS
1:
next
prim max
pop %eax
cmpl %eax, ToS
jg 1f
mov %eax, ToS
1:
next
prim umin // uint uint -- uint
pop %eax
cmpl %eax, ToS
jb 1f
mov %eax, ToS
1:
next
prim umax
pop %eax
cmpl %eax, ToS
ja 1f
mov %eax, ToS
1:
next
prim sumCells, "sum-cells" # array count -- int
mov ToS, %ecx
pop %edx
xor %eax, %eax
1:
jcxz 2f
dec %ecx
add %edx, %eax
jmp 1b
2:
mov %eax, ToS
next
# Data Stack manipulation prims ######################
prim dspGet, "dsp@"
push ToS
mov %esp, ToS
next
prim dspSet, "dsp!"
mov ToS, %esp
pop ToS
next
prim dsDepth, "ds-depth"
push ToS
mov var_ds0, ToS
sub %esp, ToS
sar $CELL_BITS, ToS
dec ToS # because ToS is in a register
next
prim drop
pop ToS
next
prim nip
lea CELL_SIZE(%esp), %esp
next
prim swap // a b -- b a
xchg ToS, (%esp)
next
.data
dupcount: DATA 0
prim dup
incl dupcount
cmp var_ds0, %esp
jae crash
push ToS
next
crash:
xor %eax, %eax
mov (%eax), %eax
prim over
push ToS
mov CELL_SIZE(%esp), ToS
next
# Return stack prims #################################
prim rspGet, "rsp@"
push ToS
mov %ebp, ToS
next
prim rspSet, "rsp!"
mov ToS, %ebp
pop ToS
next
prim rsDepth, "rs-depth"
push ToS
mov var_rs0, ToS
sub %ebp, ToS
sar $CELL_BITS, ToS
next
prim push
pushrs ToS
pop ToS
next
prim peek
push ToS
mov (%ebp), ToS
next
prim pop
push ToS
poprs ToS
next
prim stash
pushrs ToS
next
prim trash
poprs %eax
next
prim wlen # addr -- n-cells
# -1 means a primitive or other non-inlinable word
# otherwise returns the length in cells of the word
mov $-1, %ecx
mov %esi, %edx
mov ToS, %esi
lodsl
cmpl $do, %eax
jne 2f
mov $endcol, %eax
xchg %esi, %edi
repne scasl
xchg %esi, %edi
not %ecx
dec %ecx
2:
mov %edx, %esi
mov %ecx, ToS
next
variable curframe
prim frame
mov curframe, %eax
pushrs %eax
mov %ebp, curframe
next
prim unframe
mov curframe, %ebp
poprs %eax
mov %eax, curframe
next
prim local, "$$" # n -- addr
# get cell n of current frame
not ToS
mov curframe, %eax
lea (%eax, ToS, CELL_SIZE), %edx
mov %edx, ToS
next
prim locals # n --
# create a frame with n local variables
mov curframe, %eax
pushrs %eax
mov %ebp, curframe
mov ToS, %ecx
1:
test %ecx, %ecx
jz 2f
pop %eax
dec %ecx
pushrs %eax
jmp 1b
2:
pushrs $do_unframe
pop ToS
next
prim incVar "inc-var"
incl (ToS)
pop ToS
next
prim decVar "dec-var"
decl (ToS)
pop ToS
next
do_unframe:
DATA unframe, return
# Instruction pointer ################################
prim ipGet, "ip@"
push ToS
mov %esi, ToS
next
# Memory access ######################################
prim get, "@"
mov (ToS), ToS
next
prim getByte, "@b"
movzbl (ToS), ToS
next
prim getStep "@+" # addr -- addr' n
mov (ToS), %eax
addl $CELL_SIZE, ToS
push ToS
mov %eax, ToS
next
prim set "!" # int addr --
pop %eax
mov %eax, (ToS)
pop ToS
next
prim setByte "!b" # int addr --
pop %edx
mov %dl, (ToS)
pop ToS
next
prim dpGet, "dp@"
push ToS
mov %edi, ToS
next
prim dpSet, "dp!"
mov ToS, %edi
pop ToS
next
prim here
push ToS
mov %edi, ToS
next
prim dpAlign, "align-dp"
align_dp
next
prim storeinc, ","
mov ToS, (%edi)
lea 4(%edi), %edi
pop ToS
next
prim storebinc, ",b"
mov %bl, (%edi)
inc %edi
pop ToS
next
prim cell
shll $CELL_BITS, ToS
next
prim align // addr -- addr
// align to cell boundary
add $(CELL_SIZE-1), ToS
andb $0xfc, %bl
next
prim isAnonymous "is-anon?" # addr -- bool
# is addr in the anonymous area?
mov var_anonCodeAreaAddr, %edx
sub %edx, ToS
xor %edx, %edx
cmp $SCRATCH_SIZE, ToS
seta %dl
dec %edx
mov %edx, ToS
next
# Flow control #######################################
prim endcol
poprs %esi
next
prim return
poprs %esi
next
prim data # -- addr
push ToS
mov (%esi), %eax
lea CELL_SIZE(%esi), ToS
lea CELL_SIZE(%esi, %eax), %esi
next
prim branch
add (%esi), %esi
next
prim zbranch # bool --
mov (%esi), %eax
#lodsl # distance to branch
add $CELL_SIZE, %esi
xor %ecx, %ecx
sub $CELL_SIZE, %eax # because lodsl incremented %esi
test ToS, ToS # bool is zero?
setnz %cl
pop ToS
dec %ecx
and %ecx, %eax # %ecx is 0 if %edx is non-zero
add %eax, %esi
next
prim tailcall, "tail:"
mov (%esi), %esi
lea CELL_SIZE(%esi), %esi
next
prim tailcallTOS, "tailcall-tos"
lea CELL_SIZE(ToS), %esi
pop ToS
next
prim call # xt --
mov ToS, %eax
pop ToS
jmp *(%eax)
next
prim inline # xt --
# TODO: this logic belongs in quote, not inline!
mov -4(%edi), %eax
cmp $quote, %eax
je prim_storeinc # don't inline quoted words!
mov ToS, %eax
pop ToS
mov %esi, %edx
lea 4(%eax), %esi
1:
lodsl
cmp $endcol, %eax
je 2f
stosl
jmp 1b
2:
mov %edx, %esi
next
# prim select "?"
# xor %edx, %edx
# xor %ecx, %ecx
# mov 8(%esp), %eax # cond
# test %eax, %eax
# setnz %dl
# setz %cl
# dec %edx
# dec %ecx
# and (%esp), %edx # else
# and 4(%esp), %ecx # then
# addl %ecx, %edx
# lea 8(%esp), %esp
# mov %edx, (%esp)
# next
# Numeric literals ###################################
prim lit
push ToS
mov (%esi), ToS
add $CELL_SIZE, %esi
next
# we give this a different name to make code easier to read
prim quote, "'"
push ToS
mov (%esi), ToS
add $CELL_SIZE, %esi
next
# Memory copying prims ###############################
prim copyBytes, "copy-bytes" # from nbytes to --
xchg %edi, ToS # save DP
pushrs %esi # save IP
pop %ecx
pop %esi
rep movsb
poprs %esi
mov ToS, %edi
pop ToS
next
prim copy, "copy" # from ncells to --
xchg %edi, ToS # save DP
pushrs %esi
pop %edi
pop %ecx