// Wave-6 slice 6-assembler: string-operation group (movs/stos/lods/scas/cmps
// with rep prefixes) — encoder expansion group
// Expected exit code: 42
section .data
src: db "HELLO", 0
dst: db 0, 0, 0, 0, 0, 0, 0, 0

section .text
global main
main:
    ; copy 6 bytes src -> dst with rep movsb
    lea rsi, [rel src]
    lea rdi, [rel dst]
    mov ecx, 6
    rep movsb
    ; scan dst for NUL with repne scasb: stops after 5 chars, rcx = 2
    lea rdi, [rel dst]
    xor eax, eax
    mov ecx, 8
    repne scasb
    mov eax, 2
    sub eax, ecx
    jnz fail
    ; compare src/dst first 5 bytes with repe cmpsb
    lea rsi, [rel src]
    lea rdi, [rel dst]
    mov ecx, 5
    repe cmpsb
    jne fail
    ; lodsb/stosb roundtrip: load 'H' and store at dst[5]
    lea rsi, [rel src]
    lodsb                ; al = 'H' (72)
    lea rdi, [rel dst+5]
    stosb                ; dst[5] = 'H'
    ; sum bytes of dst: 'H','E','L','L','O','H' = 72+69+76+76+79+72 = 444
    lea rsi, [rel dst]
    xor ebx, ebx
    mov ecx, 6
sum_loop:
    lodsb
    movzx edx, al
    add ebx, edx
    dec ecx
    jnz sum_loop
    cmp ebx, 444
    jne fail
    mov eax, 42
    ret
fail:
    mov eax, 1
    ret
