section .data
    array db 'abdcababdc'  ; 배열 데이터
    len_of_array equ $ - array
    temp_array times 2 * len_of_array db 0
    len_of_temp_array equ $ - temp_array
    print_array db 0
    len_of_print_array equ $ - print_array

section .bss
    num_string resb 6             

section .text
    global _start

_start:
    xor rsi, rsi                 ; rsi 초기화
    mov rcx, len_of_array        ; rcx에 배열의 길이 저장
    xor R8, R8 ;splice
    xor R9, R9 ;count 
    xor R10, R10 ;boolean
    xor R13, R13 ;temp_array, arrray index용
    mov R14, 100 ;min_output
    xor R15, R15 
    mov R8, 1

.find_min_splice:
    add R10, 1
    xor R13, R13

.splice_loop:
    xor R11, R11
    xor R12, R12
    
    xor R15, R15
    add R15, rsi
    add R15, R13 
    cmp R15, len_of_array
    jg .temp_different
    
    movzx r12d, byte [array + rsi + R13] 
    movzx R11d, byte [temp_array + R13]
    cmp R11, R12
    je .loop_equal
    jmp .temp_different

.loop_equal:
    add R13, 1
    cmp R13, R8
    jne .splice_loop
    jmp .temp_equal

.temp_equal:
    jmp .need_number_check
    
.temp_different:
    add R9, R8
    mov R13, 0 

.temp_different_loop:
    movzx r12d, byte [array + rsi + R13]     
    mov byte [temp_array +R13], R12b
    add R13, 1
    cmp R13, R8
    jne .temp_different_loop
    cmp rsi, 0 
    je .next_rsi ;첫번째 글자 일시, R10 리셋 하지 말기 
    jmp .reset_r10

.reset_r10:
    mov R10, 1
    jmp .next_rsi

.need_number_check:
    cmp R10, 1 ; 2이상이면 
    jg .need_number
    jmp .next_rsi

.need_number:
    cmp R10, 2
    je .need_number_1
    cmp R10, 10
    je .need_number_10
    cmp R10, 100
    je .need_number_100
    jmp .next_rsi
    
.need_number_1:
    add R9, 1
    jmp .next_rsi
    
.need_number_10:
    add R9, 1
    jmp .next_rsi

.need_number_100:
    add R9, 1
    jmp .next_rsi
    
.next_rsi:
    mov rcx, len_of_print_array   
    add rsi, R8
    cmp rsi, len_of_array 
    jl .find_min_splice
    cmp rsi, len_of_array 
    jg .flush_add_R8
    jmp .compare_output

.flush_add_R8:
    mov RAX, rsi 
    sub RAX, len_of_array
    sub R9, RAX
    xor RAX, RAX

.compare_output:
    xor rsi, rsi
    cmp R9, R14 ;
    jl .min 
    jmp .next_splice

.min :
    mov R14, R9
    mov R15, R8

.next_splice:
    add R8, 1
    xor R9, R9
    xor rsi, rsi
    xor R10, R10
    cmp R8, len_of_array ;
    jle .find_min_splice
    mov [print_array], R14


print_loop:
    movzx eax, byte [print_array + rsi]
    call print_number

    inc rsi                       
    loop print_loop                
    
    mov eax, 60                   
    xor edi, edi                  
    syscall                        


%macro print 2
    mov rax, 1
    mov rdi, 1
    mov rsi, %1
    mov rdx, %2
    syscall
%endmacro

print_number:
    push rsi
    push rcx

    mov rdi, num_string + 5       
    mov byte [rdi], 0              
    mov rcx, 10                    
    
convert_loop:
    dec rdi                       
    xor rdx, rdx                   
    div rcx                        
    add dl, '0'                    
    mov [rdi], dl                  
    test rax, rax                  
    jnz convert_loop               

    mov rsi, rdi                   
    lea rdx, [num_string + 6]     
    sub rdx, rsi                   
    print rsi, rdx                 

    pop rcx
    pop rsi
    ret

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: