-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheme.s
1188 lines (988 loc) · 17.4 KB
/
scheme.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
;;; scheme.s
;;; Support for the Scheme compiler
;;;
;;; Programmer: Mayer Goldberg, 2018
%define T_UNDEFINED 0
%define T_VOID 1
%define T_NIL 2
%define T_INTEGER 3
%define T_FRACTION 4
%define T_BOOL 5
%define T_CHAR 6
%define T_STRING 7
%define T_SYMBOL 8
%define T_CLOSURE 9
%define T_PAIR 10
%define T_VECTOR 11
%define T_BUCKET 12
%define CHAR_NUL 0
%define CHAR_TAB 9
%define CHAR_NEWLINE 10
%define CHAR_PAGE 12
%define CHAR_RETURN 13
%define CHAR_SPACE 32
%define TYPE_BITS 4
%define WORD_SIZE 64
%define MAKE_LITERAL(type, lit) ((lit << TYPE_BITS) | type)
%macro TYPE 1
and %1, ((1 << TYPE_BITS) - 1)
%endmacro
%macro DATA 1
sar %1, TYPE_BITS
%endmacro
%macro DATA_UPPER 1
shr %1, (((WORD_SIZE - TYPE_BITS) >> 1) + TYPE_BITS)
%endmacro
%macro DATA_LOWER 1
shl %1, ((WORD_SIZE - TYPE_BITS) >> 1)
DATA_UPPER %1
%endmacro
%define MAKE_LITERAL_PAIR(car, cdr) (((((car - start_of_data) << ((WORD_SIZE - TYPE_BITS) >> 1)) | (cdr - start_of_data)) << TYPE_BITS) | T_PAIR)
%define MAKE_LITERAL_SYMBOL(bucket) (((bucket - start_of_data) << TYPE_BITS) | T_SYMBOL)
%define MAKE_LITERAL_FRACTION(numerator, denominator) (((((numerator - start_of_data) << ((WORD_SIZE - TYPE_BITS) >> 1)) | (denominator - start_of_data)) << TYPE_BITS) | T_FRACTION)
%macro CALL_LIB_FUN 2
push %2
mov rbx, %1
mov rbx, [rbx]
CLOSURE_ENV rbx
push rbx
mov %1 , [%1]
CLOSURE_CODE %1
call %1
%endmacro
%macro GCD 2
push %2
push %1
call gcd
pop %1
pop %2
%endmacro
%macro CLEAN_STACK 0
mov rbx, [rbp + 3*8] ; n
leave
pop rdx ;save return
shl rbx,3
add rbx, 8*3
add rsp, rbx ; clen stack
push rdx ; push return
%endmacro
%macro NEG_FRACTION 1
mov rax, [%1]
CAR rax
DATA rax
neg rax
MAKE_INT rax
mov r8, rax
test_malloc 8
mov [rax], r8
mov r8, [%1]
packed_cdr r8
MAKE_FRACTION rax, r8
mov r8, rax
test_malloc 8
mov [rax],r8
mov %1, rax
%endmacro
%macro test_malloc 1
push rcx
push rbx
mov rbx, malloc_pointer
mov rax, qword [rbx]
mov rcx, qword [rbx]
add rcx, %1
mov qword [rbx], rcx
pop rbx
pop rcx
%endmacro
%macro REDUCE 1
push rcx
push rdx
push r8
push r10
mov rcx, %1
mov rdx, %1
packed_car rcx
packed_cdr rdx
mov qword[a],rcx
mov qword[b],rdx
mov rcx,[rcx]
DATA rcx
mov rdx,[rdx]
DATA rdx
mov r10, rdx ; b
cmp rcx, 0
jg %%positive
neg rcx
%%positive:
GCD rcx, rdx
mov r8, rax ; gcd
mov rax, rcx
xor rdx,rdx
div r8
mov rcx,qword[a]
mov rcx,[rcx]
DATA rcx
cmp rcx, 0
jg %%positive_2
neg rax
%%positive_2:
mov rcx, rax ; rcx <= rcx/gcd
mov rax, r10 ; rax <= b
xor rdx, rdx
div r8 ; rax <= b/gcd
mov rdx, qword[b]
MAKE_INT rax
mov [rdx], rax
mov rax, rcx
mov rcx, qword[a]
MAKE_INT rax
mov [rcx],rax
pop r10
pop r8
pop rdx
pop rcx
%endmacro
%macro MAKE_INT 1
shl %1, TYPE_BITS
or %1, T_INTEGER
%endmacro
%macro MAKE_CHAR 1
shl %1, TYPE_BITS
or %1, T_CHAR
%endmacro
%macro MUL_FRACTION 2
mov qword[a], %1
mov qword[b], %2
mov r8, [%1]
mov r9, [%2]
CAR r8
DATA r8
CAR r9
DATA r9
mov rax, r8
mul r9
mov r9, rax
MAKE_INT r9
test_malloc 8
mov [rax], r9
mov r9, rax
mov %1, qword[a]
mov %2, qword[b]
mov rax, [%1]
mov r8, [%2]
CDR rax
DATA rax
CDR r8
DATA r8
mul r8
mov r8, rax
MAKE_INT r8
test_malloc 8
mov [rax], r8
mov %1, r9
mov %2, rax
%endmacro
%macro ADD_FRACTION 2
mov qword[a], %1
mov qword[b], %2
mov r8, [%1]
mov r9, [%2]
CAR r8
DATA r8
CDR r9
DATA r9
mov rax, r8
mul r9
mov r9, rax
mov %1, qword[a]
mov %2, qword[b]
mov rax, [%1]
mov r8, [%2]
CDR rax
DATA rax
CAR r8
DATA r8
mul r8
add rax, r9
mov r9, rax
MAKE_INT r9
mov %1, qword[a]
mov %2, qword[b]
mov rax, [%1]
mov r8, [%2]
CDR rax
DATA rax
CDR r8
DATA r8
mul r8
mov r8, rax
MAKE_INT r8
test_malloc 8
mov [rax], r8
mov %2, rax
test_malloc 8
mov [rax], r9
mov %1, rax
%endmacro
%macro REMOVE_FRACTION 1
mov rax, %1
CDR rax
DATA rax
cmp rax, 1
je %%remove
mov rax, %1
jmp %%finish
%%remove:
mov rax, %1
CAR rax
%%finish:
mov %1, rax
%endmacro
%macro MAKE_FRACTION 2
sub %1, start_of_data
shl %1, (((WORD_SIZE - TYPE_BITS) >> 1) + TYPE_BITS)
sub %2, start_of_data
shl %2, TYPE_BITS
or %1, %2
or %1, T_FRACTION
%endmacro
%macro MAKE_PAIR 2
sub %1, start_of_data
shl %1, (((WORD_SIZE - TYPE_BITS) >> 1) + TYPE_BITS)
sub %2, start_of_data
shl %2, TYPE_BITS
or %1, %2
or %1, T_PAIR
%endmacro
%define MAKE_SYMBOL_BUCKET(str, last) (((((str - start_of_data) << ((WORD_SIZE - TYPE_BITS) >> 1)) | (last - start_of_data)) << TYPE_BITS) | T_SYMBOL)
%macro MAKE_BUCKET 2
sub %1, start_of_data
shl %1, (((WORD_SIZE - TYPE_BITS) >> 1) + TYPE_BITS)
sub %2, start_of_data
shl %2, TYPE_BITS
or %1, %2
or %1, T_SYMBOL
%endmacro
%macro packed_car 1
DATA_UPPER %1
add %1, start_of_data
%endmacro
%macro CAR 1
DATA_UPPER %1
add %1, start_of_data
mov %1, qword [%1]
%endmacro
%macro packed_cdr 1
DATA_LOWER %1
add %1, start_of_data
%endmacro
%macro CDR 1
DATA_LOWER %1
add %1, start_of_data
mov %1, qword [%1]
%endmacro
;;; MAKE_LITERAL_CLOSURE target, env, code
%macro MAKE_LITERAL_CLOSURE 3
push rax
push rbx
mov rax, %1
mov qword [rax], %2
sub qword [rax], start_of_data
shl qword [rax], ((WORD_SIZE - TYPE_BITS) >> 1)
lea rbx, [rax + 8]
sub rbx, start_of_data
or qword [rax], rbx
shl qword [rax], TYPE_BITS
or qword [rax], T_CLOSURE
mov qword [rax + 8], %3
pop rbx
pop rax
%endmacro
%macro CLOSURE_ENV 1
DATA_UPPER %1
add %1, start_of_data
%endmacro
%macro CLOSURE_CODE 1
DATA_LOWER %1
add %1, start_of_data
mov %1, qword [%1]
%endmacro
%macro CHECK_CLOSURE 0
mov rax, [rax]
mov rbx, rax
TYPE rax
cmp rax, T_CLOSURE
JNE ERROR_NOT_CLOSURE
mov rax, rbx
xor r11, r11
xor r12, r12
%endmacro
%macro MAKE_LITERAL_STRING 1+
dq (((((%%LstrEnd - %%Lstr) << ((WORD_SIZE - TYPE_BITS) >> 1)) | (%%Lstr - start_of_data)) << TYPE_BITS) | T_STRING)
%%Lstr:
db %1
%%LstrEnd:
%endmacro
%macro MAKE_VECTOR 2
sub %2, %1
shr %2, 3
shl %2, ((WORD_SIZE - TYPE_BITS) >> 1)
sub %1, start_of_data
or %2, %1
shl %2, TYPE_BITS
or %2, T_VECTOR
%endmacro
%macro MAKE_STRING 2
sub %2, %1
shl %2, ((WORD_SIZE - TYPE_BITS) >> 1)
sub %1, start_of_data
or %2, %1
shl %2, TYPE_BITS
or %2, T_STRING
%endmacro
%macro STRING_LENGTH 1
DATA_UPPER %1
%endmacro
%macro STRING_ELEMENTS 1
DATA_LOWER %1
add %1, start_of_data
%endmacro
%macro STR_CMPR 2
push %2
mov r10, %1
mov r12, %2
STRING_LENGTH r10
STRING_LENGTH r12
cmp r10, r12
jne %%not_equal
STRING_ELEMENTS %1
STRING_ELEMENTS %2
mov rdi, r10
%%loop:
cmp rdi,0
je %%equal
mov cl, byte [%1]
cmp cl, byte [%2]
jne %%not_equal
inc %1
inc %2
dec rdi
jmp %%loop
%%not_equal:
mov r10, 1
mov r12, 2
cmp r10, r12
jmp %%finish
%%equal:
cmp rax, rax
%%finish:
pop %2
%endmacro
%macro MAKE_LITERAL_VECTOR 1+
dq ((((((%%VecEnd - %%Vec) >> 3) << ((WORD_SIZE - TYPE_BITS) >> 1)) | (%%Vec - start_of_data)) << TYPE_BITS) | T_VECTOR)
%%Vec:
dq %1
%%VecEnd:
%endmacro
%macro VECTOR_LENGTH 1
DATA_UPPER %1
%endmacro
%macro VECTOR_ELEMENTS 1
DATA_LOWER %1
add %1, start_of_data
%endmacro
%macro VECTOR_REF 3
mov %1, %2
VECTOR_ELEMENTS %1
lea %1, [%1 + %3*8]
mov %1, qword [%1]
%endmacro
%macro STRING_REF 3
push rax
mov rax, %2
STRING_ELEMENTS rax
add rax, %3
mov %1, byte [rax]
pop rax
%endmacro
%define SOB_UNDEFINED MAKE_LITERAL(T_UNDEFINED, 0)
%define SOB_VOID MAKE_LITERAL(T_VOID, 0)
%define SOB_FALSE MAKE_LITERAL(T_BOOL, 0)
%define SOB_TRUE MAKE_LITERAL(T_BOOL, 1)
%define SOB_NIL MAKE_LITERAL(T_NIL, 0)
%define gigabyte(n) n << 30
section .data
start_of_data:
a:
dq 0
b:
dq 0
sobNil:
dq SOB_NIL
sobInt3:
dq MAKE_LITERAL(T_INTEGER, 3)
sobInt2:
dq MAKE_LITERAL(T_INTEGER, 2)
sobInt1:
dq MAKE_LITERAL(T_INTEGER, 1)
sobPair3N:
dq MAKE_LITERAL_PAIR(sobInt3, sobNil)
sobPair23N:
dq MAKE_LITERAL_PAIR(sobInt2, sobPair3N)
sobPair123N:
dq MAKE_LITERAL_PAIR(sobInt1, sobPair23N)
sobPair12:
dq MAKE_LITERAL_PAIR(sobInt1, sobInt2)
sobPairA:
dq MAKE_LITERAL_PAIR(sobPair12, sobNil)
sobPairB:
dq MAKE_LITERAL_PAIR(sobPair123N, sobPairA)
sobPairC:
dq MAKE_LITERAL_PAIR(sobInt3, sobPair12)
sobPairNN:
dq MAKE_LITERAL_PAIR(sobNil, sobNil)
sob1:
dq MAKE_LITERAL_PAIR(sobInt1, sobPairNN)
sob2:
dq MAKE_LITERAL_PAIR(sobInt2, sob1)
sob3:
dq MAKE_LITERAL_PAIR(sob2, sob2)
sob4:
dq MAKE_LITERAL_PAIR(sobInt1, sobNil)
sob5:
dq MAKE_LITERAL_PAIR(sob4, sobNil)
sob6:
dq 0, 0 ; closure: wait for later!
sob7:
MAKE_LITERAL_STRING "Mayer", CHAR_NEWLINE, "Goldberg", CHAR_TAB, "<=="
sob8:
dq MAKE_LITERAL_PAIR(sob7, sobPairB)
sobVec1:
MAKE_LITERAL_VECTOR sob8, sob7, sobInt1, sobInt2, sobInt3, sob4
section .bss
malloc_pointer:
resq 1
start_of_data2:
resb gigabyte(1)
extern exit, printf, scanf, malloc
global _main, write_sob, write_sob_if_not_void
section .text
_main:
nop
; setup a fake closure just to see how it prints:
mov rax, 0x1234
sal rax, 30
or rax, sob6 + 8 - start_of_data
sal rax, 4
or rax, T_CLOSURE
mov qword [sob6], rax
mov qword [sob6 + 8], main
; printing the fake closure:
push qword [sob6]
call write_sob_if_not_void
add rsp, 1*8
; printing a vector:
push qword [sobVec1]
call write_sob_if_not_void
add rsp, 1*8
; will void print??
push qword SOB_VOID
call write_sob_if_not_void
add rsp, 1*8
ret
write_sob_undefined:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .undefined
call printf
leave
ret
section .data
.undefined:
db "#<undefined>", 0
write_sob_integer:
push rbp
mov rbp, rsp
mov rsi, qword [rbp + 8 + 1*8]
sar rsi, TYPE_BITS
mov rdi, .int_format_string
mov rax, 0
call printf
leave
ret
section .data
.int_format_string:
db "%ld", 0
write_sob_char:
push rbp
mov rbp, rsp
mov rsi, qword [rbp + 8 + 1*8]
DATA rsi
cmp rsi, CHAR_NUL
je .Lnul
cmp rsi, CHAR_TAB
je .Ltab
cmp rsi, CHAR_NEWLINE
je .Lnewline
cmp rsi, CHAR_PAGE
je .Lpage
cmp rsi, CHAR_RETURN
je .Lreturn
cmp rsi, CHAR_SPACE
je .Lspace
jg .Lregular
mov rdi, .special
jmp .done
.Lnul:
mov rdi, .nul
jmp .done
.Ltab:
mov rdi, .tab
jmp .done
.Lnewline:
mov rdi, .newline
jmp .done
.Lpage:
mov rdi, .page
jmp .done
.Lreturn:
mov rdi, .return
jmp .done
.Lspace:
mov rdi, .space
jmp .done
.Lregular:
mov rdi, .regular
jmp .done
.done:
mov rax, 0
call printf
leave
ret
section .data
.space:
db "#\space", 0
.newline:
db "#\newline", 0
.return:
db "#\return", 0
.tab:
db "#\tab", 0
.page:
db "#\page", 0
.nul:
db "#\nul", 0
.special:
db "#\x%x", 0
.regular:
db "#\%c", 0
write_sob_void:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .void
call printf
leave
ret
section .data
.void:
db "#<void>", 0
write_sob_bool:
push rbp
mov rbp, rsp
mov rax, qword [rbp + 8 + 1*8]
cmp rax, SOB_FALSE
je .sobFalse
mov rdi, .true
jmp .continue
.sobFalse:
mov rdi, .false
.continue:
mov rax, 0
call printf
leave
ret
section .data
.false:
db "#f", 0
.true:
db "#t", 0
write_sob_nil:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .nil
call printf
leave
ret
section .data
.nil:
db "()", 0
write_sob_string:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .double_quote
call printf
mov rax, qword [rbp + 8 + 1*8]
mov rcx, rax
STRING_LENGTH rcx
STRING_ELEMENTS rax
.loop:
cmp rcx, 0
je .done
mov bl, byte [rax]
and rbx, 0xff
cmp rbx, CHAR_TAB
je .ch_tab
cmp rbx, CHAR_NEWLINE
je .ch_newline
cmp rbx, CHAR_PAGE
je .ch_page
cmp rbx, CHAR_RETURN
je .ch_return
cmp rbx, CHAR_SPACE
jl .ch_hex
mov rdi, .fs_simple_char
mov rsi, rbx
jmp .printf
.ch_hex:
mov rdi, .fs_hex_char
mov rsi, rbx
jmp .printf
.ch_tab:
mov rdi, .fs_tab
mov rsi, rbx
jmp .printf
.ch_page:
mov rdi, .fs_page
mov rsi, rbx
jmp .printf
.ch_return:
mov rdi, .fs_return
mov rsi, rbx
jmp .printf
.ch_newline:
mov rdi, .fs_newline
mov rsi, rbx
.printf:
push rax
push rcx
mov rax, 0
call printf
pop rcx
pop rax
dec rcx
inc rax
jmp .loop
.done:
mov rax, 0
mov rdi, .double_quote
call printf
leave
ret
section .data
.double_quote:
db '"', 0
.fs_simple_char:
db "%c", 0
.fs_hex_char:
db "\x%02x;", 0
.fs_tab:
db "\t", 0
.fs_page:
db "\f", 0
.fs_return:
db "\r", 0
.fs_newline:
db "\n", 0
write_sob_pair:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .open_paren
call printf
mov rax, qword [rbp + 8 + 1*8]
CAR rax
push rax
call write_sob
add rsp, 1*8
mov rax, qword [rbp + 8 + 1*8]
CDR rax
push rax
call write_sob_pair_on_cdr
add rsp, 1*8
mov rdi, .close_paren
mov rax, 0
call printf
leave
ret
section .data
.open_paren:
db "(", 0
.close_paren:
db ")", 0
write_sob_pair_on_cdr:
push rbp
mov rbp, rsp
mov rbx, qword [rbp + 8 + 1*8]
mov rax, rbx
TYPE rbx
cmp rbx, T_NIL
je .done
cmp rbx, T_PAIR
je .cdrIsPair
push rax
mov rax, 0
mov rdi, .dot
call printf
call write_sob
add rsp, 1*8
jmp .done
.cdrIsPair:
mov rbx, rax
CDR rbx
push rbx
CAR rax
push rax
mov rax, 0
mov rdi, .space
call printf
call write_sob
add rsp, 1*8
call write_sob_pair_on_cdr
add rsp, 1*8
.done:
leave
ret
section .data
.space:
db " ", 0
.dot:
db " . ", 0
write_sob_vector:
push rbp
mov rbp, rsp
mov rax, 0
mov rdi, .fs_open_vector
call printf
mov rax, qword [rbp + 8 + 1*8]
mov rcx, rax
VECTOR_LENGTH rcx
cmp rcx, 0
je .done
VECTOR_ELEMENTS rax
push rcx
push rax
mov rax, qword [rax]
push qword [rax]
call write_sob
add rsp, 1*8
pop rax
pop rcx
dec rcx
add rax, 8
.loop:
cmp rcx, 0
je .done
push rcx
push rax
mov rax, 0
mov rdi, .fs_space
call printf
pop rax
push rax
mov rax, qword [rax]
push qword [rax]
call write_sob
add rsp, 1*8
pop rax
pop rcx
dec rcx
add rax, 8
jmp .loop
.done:
mov rax, 0
mov rdi, .fs_close_vector
call printf
leave
ret
section .data
.fs_open_vector:
db "#(", 0
.fs_close_vector:
db ")", 0
.fs_space:
db " ", 0
write_sob_symbol:
push rbp
mov rbp, rsp
mov rax, qword[rbp +8 + 1*8]
CAR rax
mov rcx, rax
STRING_LENGTH rcx
STRING_ELEMENTS rax
.loop:
cmp rcx, 0
je .done
mov bl, byte [rax]
and rbx, 0xff