fcoreutils 0.22.0

High-performance GNU coreutils replacement with SIMD and parallelism
Documentation
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
; ============================================================
; fprintf_unified.asm — GNU-compatible 'printf' command
; Builds with: nasm -f bin fprintf_unified.asm -o fprintf
;
; printf: Format and print data.
;
; Register allocation:
;   r14d = argc, r15 = argv
;   r12  = format string pointer
;   r13d = current argument index (for format args)
;   ebx  = scratch / flags
; ============================================================

BITS 64
ORG 0x400000

%define SYS_WRITE           1
%define SYS_EXIT            60
%define SYS_RT_SIGPROCMASK  14

%define STDOUT          1
%define STDERR          2
%define SIG_BLOCK       0
%define SIGPIPE        13

; BSS layout: 0x500000
%define BSS_ADDR       0x500000
%define BSS_SIZE       16384
%define OUT_BUF        BSS_ADDR                ; 8192 bytes
%define NUM_BUF        (BSS_ADDR + 8192)       ; 128 bytes
%define OUT_POS        (BSS_ADDR + 8320)       ; 8 bytes
%define FMT_SPEC       (BSS_ADDR + 8328)       ; 64 bytes - format spec buffer

; --- ELF Header (64 bytes) ---
ehdr:
    db 0x7f, 'E','L','F'
    db 2, 1, 1, 0
    dq 0
    dw 2, 0x3e
    dd 1
    dq _start
    dq phdr - $$
    dq 0
    dd 0
    dw 64, 56, 3, 64, 0, 0

; --- Program Headers ---
phdr:
    ; PT_LOAD: code + data (R+X)
    dd 1, 5
    dq 0, $$, $$, file_size, file_size, 0x200000

    ; PT_LOAD: BSS (R+W)
    dd 1, 6
    dq 0, BSS_ADDR, BSS_ADDR, 0, BSS_SIZE, 0x200000

    ; PT_GNU_STACK (NX)
    dd 0x6474e551, 6
    dq 0, 0, 0, 0, 0, 0x10

; ============================================================
; Code
; ============================================================
_start:
    ; Block SIGPIPE
    sub     rsp, 16
    mov     qword [rsp], 0
    bts     qword [rsp], SIGPIPE
    mov     eax, SYS_RT_SIGPROCMASK
    mov     edi, SIG_BLOCK
    mov     rsi, rsp
    xor     edx, edx
    mov     r10d, 8
    syscall
    add     rsp, 16

    ; Save argc/argv
    mov     r14d, [rsp]
    lea     r15, [rsp + 8]

    ; Check argc
    cmp     r14d, 2
    jl      err_missing_operand

    ; Check for --help and --version
    mov     rdi, [r15 + 8]      ; argv[1]
    push    rdi
    mov     rsi, str_help_flag
    call    str_eq
    test    eax, eax
    pop     rdi
    jnz     show_help
    push    rdi
    mov     rsi, str_version_flag
    call    str_eq
    test    eax, eax
    pop     rdi
    jnz     show_version

    ; argv[1] is the format string
    mov     r12, [r15 + 8]
    mov     r13d, 2              ; first data arg index

    ; Initialize output buffer
    mov     qword [OUT_POS], 0

    ; Process format string (may repeat if more args than specifiers)
.format_loop:
    mov     rdi, r12             ; reset to start of format

.process_char:
    movzx   eax, byte [rdi]
    test    al, al
    jz      .format_done_check
    cmp     al, '%'
    je      .handle_percent
    cmp     al, '\'
    je      .handle_escape
    ; Regular character
    push    rdi
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.handle_escape:
    inc     rdi
    movzx   eax, byte [rdi]
    test    al, al
    jz      .format_done_check
    cmp     al, '\'
    je      .esc_bslash
    cmp     al, 'n'
    je      .esc_nl
    cmp     al, 't'
    je      .esc_tab
    cmp     al, 'r'
    je      .esc_cr
    cmp     al, 'a'
    je      .esc_bell
    cmp     al, 'b'
    je      .esc_bs
    cmp     al, 'f'
    je      .esc_ff
    cmp     al, 'v'
    je      .esc_vt
    cmp     al, 'c'
    je      .esc_stop          ; \c stops output
    cmp     al, '0'
    je      .esc_octal
    cmp     al, 'x'
    je      .esc_hex
    ; Unknown escape: output backslash + char
    push    rdi
    mov     al, '\'
    call    buf_putc
    pop     rdi
    movzx   eax, byte [rdi]
    push    rdi
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_bslash:
    push    rdi
    mov     al, '\'
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_nl:
    push    rdi
    mov     al, 10
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_tab:
    push    rdi
    mov     al, 9
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_cr:
    push    rdi
    mov     al, 13
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_bell:
    push    rdi
    mov     al, 7
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_bs:
    push    rdi
    mov     al, 8
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_ff:
    push    rdi
    mov     al, 12
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_vt:
    push    rdi
    mov     al, 11
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

.esc_stop:
    ; \c: flush and exit
    call    buf_flush
    xor     edi, edi
    jmp     do_exit

.esc_octal:
    ; \0NNN: parse up to 3 octal digits after the 0
    inc     rdi                 ; skip '0'
    xor     ecx, ecx            ; accumulator
    xor     r8d, r8d            ; digit count
.esc_oct_loop:
    cmp     r8d, 3
    jge     .esc_oct_done
    movzx   eax, byte [rdi]
    sub     al, '0'
    cmp     al, 7
    ja      .esc_oct_done
    shl     ecx, 3
    add     ecx, eax
    inc     rdi
    inc     r8d
    jmp     .esc_oct_loop
.esc_oct_done:
    push    rdi
    mov     al, cl
    call    buf_putc
    pop     rdi
    jmp     .process_char

.esc_hex:
    ; \xHH: parse up to 2 hex digits
    inc     rdi                 ; skip 'x'
    xor     ecx, ecx
    xor     r8d, r8d
.esc_hex_loop:
    cmp     r8d, 2
    jge     .esc_hex_done
    movzx   eax, byte [rdi]
    cmp     al, '0'
    jl      .esc_hex_done
    cmp     al, '9'
    jle     .esc_hex_digit
    cmp     al, 'a'
    jl      .esc_hex_try_upper
    cmp     al, 'f'
    jg      .esc_hex_done
    sub     al, ('a' - 10)
    jmp     .esc_hex_acc
.esc_hex_try_upper:
    cmp     al, 'A'
    jl      .esc_hex_done
    cmp     al, 'F'
    jg      .esc_hex_done
    sub     al, ('A' - 10)
    jmp     .esc_hex_acc
.esc_hex_digit:
    sub     al, '0'
.esc_hex_acc:
    shl     ecx, 4
    add     ecx, eax
    inc     rdi
    inc     r8d
    jmp     .esc_hex_loop
.esc_hex_done:
    push    rdi
    mov     al, cl
    call    buf_putc
    pop     rdi
    jmp     .process_char

; ---- Format specifier handling ----
.handle_percent:
    inc     rdi
    movzx   eax, byte [rdi]
    cmp     al, '%'
    je      .pct_literal
    cmp     al, 0
    je      .format_done_check

    ; Save format pointer, skip flags/width/precision
    mov     r8, rdi             ; save start after %

    ; Skip flags: -, +, space, 0, #
.skip_flags:
    movzx   eax, byte [rdi]
    cmp     al, '-'
    je      .skip_flag_next
    cmp     al, '+'
    je      .skip_flag_next
    cmp     al, ' '
    je      .skip_flag_next
    cmp     al, '0'
    je      .skip_flag_next
    cmp     al, '#'
    je      .skip_flag_next
    jmp     .skip_width
.skip_flag_next:
    inc     rdi
    jmp     .skip_flags

    ; Skip width (digits or *)
.skip_width:
    movzx   eax, byte [rdi]
    cmp     al, '*'
    je      .skip_width_star
    cmp     al, '0'
    jl      .check_precision
    cmp     al, '9'
    jg      .check_precision
    inc     rdi
    jmp     .skip_width
.skip_width_star:
    inc     rdi

.check_precision:
    cmp     byte [rdi], '.'
    jne     .got_conversion
    inc     rdi
    ; Skip precision digits or *
.skip_prec:
    movzx   eax, byte [rdi]
    cmp     al, '*'
    je      .skip_prec_star
    cmp     al, '0'
    jl      .got_conversion
    cmp     al, '9'
    jg      .got_conversion
    inc     rdi
    jmp     .skip_prec
.skip_prec_star:
    inc     rdi

.got_conversion:
    ; rdi points at conversion char
    movzx   eax, byte [rdi]
    cmp     al, 's'
    je      .conv_s
    cmp     al, 'd'
    je      .conv_d
    cmp     al, 'i'
    je      .conv_d
    cmp     al, 'u'
    je      .conv_u
    cmp     al, 'o'
    je      .conv_o
    cmp     al, 'x'
    je      .conv_x
    cmp     al, 'X'
    je      .conv_X
    cmp     al, 'c'
    je      .conv_c
    cmp     al, 'f'
    je      .conv_f_stub
    cmp     al, 'e'
    je      .conv_f_stub
    cmp     al, 'g'
    je      .conv_f_stub
    ; Unknown conversion: output literally
    push    rdi
    mov     al, '%'
    call    buf_putc
    pop     rdi
    jmp     .process_char

.pct_literal:
    push    rdi
    mov     al, '%'
    call    buf_putc
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %s: string ----
.conv_s:
    push    rdi
    ; Get next argument (or empty string if exhausted)
    cmp     r13d, r14d
    jge     .conv_s_empty
    mov     rsi, [r15 + r13*8]
    inc     r13d
    ; Write the string
    mov     rdi, rsi
    push    rsi
    call    str_len
    pop     rsi
    mov     edx, eax
    call    buf_write_n
    pop     rdi
    inc     rdi
    jmp     .process_char

.conv_s_empty:
    ; No more args - output nothing
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %d / %i: signed decimal ----
.conv_d:
    push    rdi
    call    get_next_int_arg
    ; rax = signed value
    test    rax, rax
    jns     .conv_d_pos
    push    rax
    mov     al, '-'
    call    buf_putc
    pop     rax
    neg     rax
.conv_d_pos:
    call    format_and_write_u64
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %u: unsigned decimal ----
.conv_u:
    push    rdi
    call    get_next_int_arg
    call    format_and_write_u64
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %o: octal ----
.conv_o:
    push    rdi
    call    get_next_int_arg
    call    format_and_write_octal
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %x: lowercase hex ----
.conv_x:
    push    rdi
    call    get_next_int_arg
    mov     ecx, 0              ; lowercase flag
    call    format_and_write_hex
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %X: uppercase hex ----
.conv_X:
    push    rdi
    call    get_next_int_arg
    mov     ecx, 1              ; uppercase flag
    call    format_and_write_hex
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %c: character ----
.conv_c:
    push    rdi
    cmp     r13d, r14d
    jge     .conv_c_empty
    mov     rsi, [r15 + r13*8]
    inc     r13d
    movzx   eax, byte [rsi]
    call    buf_putc
.conv_c_empty:
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- %f/%e/%g stub: just output "0.000000" or arg as string ----
.conv_f_stub:
    push    rdi
    cmp     r13d, r14d
    jge     .conv_f_default
    mov     rsi, [r15 + r13*8]
    inc     r13d
    ; Try to parse as integer + print with .000000
    mov     rdi, rsi
    call    parse_int
    test    rax, rax
    jns     .conv_f_pos
    push    rax
    mov     al, '-'
    call    buf_putc
    pop     rax
    neg     rax
.conv_f_pos:
    call    format_and_write_u64
    mov     rsi, str_dotzeroes
    mov     edx, 7
    call    buf_write_n
    pop     rdi
    inc     rdi
    jmp     .process_char

.conv_f_default:
    mov     rsi, str_fzero
    mov     edx, str_fzero_len
    call    buf_write_n
    pop     rdi
    inc     rdi
    jmp     .process_char

; ---- End of format string ----
.format_done_check:
    ; If there are still remaining args, re-process format
    cmp     r13d, r14d
    jl      .format_loop

    ; Flush and exit
    call    buf_flush
    xor     edi, edi
    jmp     do_exit

; ============================================================
; Argument parsing helpers
; ============================================================

; get_next_int_arg: get next argv argument as integer
; Returns: rax = parsed value
get_next_int_arg:
    cmp     r13d, r14d
    jge     .gnia_zero
    mov     rdi, [r15 + r13*8]
    inc     r13d

    ; Check for leading ' or " (character value)
    movzx   eax, byte [rdi]
    cmp     al, "'"
    je      .gnia_charval
    cmp     al, '"'
    je      .gnia_charval

    call    parse_int
    ret

.gnia_charval:
    movzx   eax, byte [rdi + 1]
    ret

.gnia_zero:
    xor     eax, eax
    ret

; parse_int: parse NUL-terminated decimal string
; Input: rdi = string, Returns: rax = value (signed)
parse_int:
    xor     rax, rax
    xor     ecx, ecx            ; sign: 0=positive, 1=negative
    movzx   edx, byte [rdi]

    ; Handle optional sign
    cmp     dl, '-'
    je      .pi_neg
    cmp     dl, '+'
    je      .pi_pos
    jmp     .pi_loop

.pi_neg:
    mov     ecx, 1
    inc     rdi
    jmp     .pi_loop

.pi_pos:
    inc     rdi

.pi_loop:
    movzx   edx, byte [rdi]
    sub     dl, '0'
    cmp     dl, 9
    ja      .pi_done
    imul    rax, 10
    movzx   edx, byte [rdi]
    sub     dl, '0'
    add     rax, rdx
    inc     rdi
    jmp     .pi_loop

.pi_done:
    test    ecx, ecx
    jz      .pi_ret
    neg     rax
.pi_ret:
    ret

; ============================================================
; Output formatting
; ============================================================

; format_and_write_u64: format rax as unsigned decimal and write
format_and_write_u64:
    lea     rcx, [NUM_BUF + 63]
    mov     byte [rcx], 0
    mov     r8d, 10
    test    rax, rax
    jnz     .fwu_loop
    dec     rcx
    mov     byte [rcx], '0'
    jmp     .fwu_write
.fwu_loop:
    test    rax, rax
    jz      .fwu_write
    xor     edx, edx
    div     r8
    add     dl, '0'
    dec     rcx
    mov     byte [rcx], dl
    jmp     .fwu_loop
.fwu_write:
    mov     rsi, rcx
    lea     edx, [NUM_BUF + 63]
    sub     edx, ecx
    call    buf_write_n
    ret

; format_and_write_octal: format rax as octal and write
format_and_write_octal:
    lea     rcx, [NUM_BUF + 63]
    mov     byte [rcx], 0
    test    rax, rax
    jnz     .fwo_loop
    dec     rcx
    mov     byte [rcx], '0'
    jmp     .fwo_write
.fwo_loop:
    test    rax, rax
    jz      .fwo_write
    mov     edx, eax
    and     edx, 7
    add     dl, '0'
    dec     rcx
    mov     byte [rcx], dl
    shr     rax, 3
    jmp     .fwo_loop
.fwo_write:
    mov     rsi, rcx
    lea     edx, [NUM_BUF + 63]
    sub     edx, ecx
    call    buf_write_n
    ret

; format_and_write_hex: format rax as hex and write
; ecx = 0 for lowercase, 1 for uppercase
format_and_write_hex:
    push    rcx                 ; save case flag
    lea     r9, [NUM_BUF + 63]
    mov     byte [r9], 0
    test    rax, rax
    jnz     .fwh_loop
    dec     r9
    mov     byte [r9], '0'
    jmp     .fwh_write
.fwh_loop:
    test    rax, rax
    jz      .fwh_write
    mov     edx, eax
    and     edx, 0xF
    cmp     edx, 10
    jl      .fwh_digit
    pop     rcx                 ; case flag
    push    rcx
    test    ecx, ecx
    jnz     .fwh_upper
    add     dl, ('a' - 10)
    jmp     .fwh_store
.fwh_upper:
    add     dl, ('A' - 10)
    jmp     .fwh_store
.fwh_digit:
    add     dl, '0'
.fwh_store:
    dec     r9
    mov     byte [r9], dl
    shr     rax, 4
    jmp     .fwh_loop
.fwh_write:
    pop     rcx                 ; clean stack
    mov     rsi, r9
    lea     edx, [NUM_BUF + 63]
    sub     rdx, r9
    call    buf_write_n
    ret

; ============================================================
; Output buffer routines
; ============================================================

; buf_putc: write single char (al) to buffer
buf_putc:
    push    rdi
    mov     rcx, [OUT_POS]
    mov     byte [OUT_BUF + rcx], al
    inc     rcx
    mov     [OUT_POS], rcx
    cmp     ecx, 8000
    jl      .bpc_done
    call    buf_flush
.bpc_done:
    pop     rdi
    ret

; buf_write_n: write edx bytes from rsi to buffer
buf_write_n:
    push    rdi
    push    r8
    mov     rcx, [OUT_POS]
    xor     eax, eax
.bwn_loop:
    cmp     eax, edx
    jge     .bwn_done
    movzx   r8d, byte [rsi + rax]
    mov     byte [OUT_BUF + rcx], r8b
    inc     rcx
    inc     eax
    cmp     ecx, 8000
    jl      .bwn_loop
    mov     [OUT_POS], rcx
    push    rsi
    push    rdx
    push    rax
    call    buf_flush
    pop     rax
    pop     rdx
    pop     rsi
    xor     ecx, ecx
    jmp     .bwn_loop
.bwn_done:
    mov     [OUT_POS], rcx
    pop     r8
    pop     rdi
    ret

buf_flush:
    mov     rcx, [OUT_POS]
    test    rcx, rcx
    jz      .bf_done
    mov     edi, STDOUT
    mov     rsi, OUT_BUF
    mov     edx, ecx
    call    do_write
    mov     qword [OUT_POS], 0
.bf_done:
    ret

; ============================================================
; Error handling
; ============================================================
err_missing_operand:
    mov     rsi, str_prefix
    mov     edx, str_prefix_len
    call    do_write_err
    mov     rsi, str_missing
    mov     edx, str_missing_len
    call    do_write_err
    mov     rsi, str_try
    mov     edx, str_try_len
    call    do_write_err
    mov     edi, 1
    jmp     do_exit

show_help:
    mov     edi, STDOUT
    mov     rsi, str_help
    mov     edx, str_help_len
    call    do_write
    xor     edi, edi
    jmp     do_exit

show_version:
    mov     edi, STDOUT
    mov     rsi, str_version
    mov     edx, str_version_len
    call    do_write
    xor     edi, edi
    jmp     do_exit

; ============================================================
; Utility functions
; ============================================================
do_write:
    mov     eax, SYS_WRITE
    syscall
    cmp     rax, -4
    je      do_write
    ret

do_write_err:
    mov     edi, STDERR
    jmp     do_write

do_exit:
    mov     eax, SYS_EXIT
    syscall

str_len:
    xor     eax, eax
.sl_loop:
    cmp     byte [rdi + rax], 0
    je      .sl_done
    inc     eax
    jmp     .sl_loop
.sl_done:
    ret

str_eq:
    xor     r8d, r8d
.se_loop:
    movzx   eax, byte [rdi + r8]
    movzx   edx, byte [rsi + r8]
    cmp     al, dl
    jne     .se_ne
    test    al, al
    jz      .se_eq
    inc     r8d
    jmp     .se_loop
.se_eq:
    mov     eax, 1
    ret
.se_ne:
    xor     eax, eax
    ret

; ============================================================
; Data
; ============================================================
; @@DATA_START@@
str_help:
    db "Usage: printf FORMAT [ARGUMENT]...", 10
    db "   or: printf OPTION", 10
    db "Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:", 10, 10
    db "      --help        display this help and exit", 10
    db "      --version     output version information and exit", 10, 10
    db "FORMAT controls the output as in C printf.  Interpreted sequences:", 10
    db '  \"      double quote', 10
    db "  \\      backslash", 10
    db "  \a      alert (BEL)", 10
    db "  \b      backspace", 10
    db "  \c      produce no further output", 10
    db "  \e      escape", 10
    db "  \f      form feed", 10
    db "  \n      new line", 10
    db "  \r      carriage return", 10
    db "  \t      horizontal tab", 10
    db "  \v      vertical tab", 10
    db "  \NNN    byte with octal value NNN (1 to 3 digits)", 10
    db "  \xHH    byte with hexadecimal value HH (1 to 2 digits)", 10
    db "  \uHHHH  Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)", 10
    db "  \UHHHHHHHH  Unicode character with hex value HHHHHHHH (8 digits)", 10
    db "  %%      a single %", 10
    db "  %b      ARGUMENT as a string with '\' escapes interpreted,", 10
    db "          except that octal escapes are of the form \0 or \0NNN", 10, 10
    db "and all C format specifications ending with one of diouxXeEfFgGaAcs.", 10
    db "ARGUMENTs are converted according to format; those following %%noneq", 10
    db "are not.  Excess ARGUMENTs are recycled through FORMAT.", 10, 10
    db "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>", 10
    db "Full documentation <https://www.gnu.org/software/coreutils/printf>", 10
    db "or available locally via: info '(coreutils) printf invocation'", 10
str_help_len equ $ - str_help

str_version:
    db "printf (GNU coreutils) 9.7", 10
    db "Copyright (C) 2025 Free Software Foundation, Inc.", 10
    db "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.", 10
    db "This is free software: you are free to change and redistribute it.", 10
    db "There is NO WARRANTY, to the extent permitted by law.", 10, 10
    db "Written by David MacKenzie.", 10
str_version_len equ $ - str_version

str_prefix:      db "printf: "
str_prefix_len   equ $ - str_prefix
str_missing:     db "missing operand", 10
str_missing_len  equ $ - str_missing
str_try:         db "Try 'printf --help' for more information.", 10
str_try_len      equ $ - str_try
; @@DATA_END@@

str_help_flag:   db "--help", 0
str_version_flag: db "--version", 0

str_dotzeroes:   db ".000000"
str_fzero:       db "0.000000"
str_fzero_len    equ $ - str_fzero

file_size equ $ - $$