; Hostess 7 + self_code iron test · never ML
bits 64
default rel
section .text
global _start

; hostess7 protocol
hostess7:
        cmp     edi, 0
        jne     .speak
        mov     eax, 7
        or      eax, 1
        ret
.speak: mov     eax, 1
        ret

; self_code protocol (H7 inside)
self_code:
        cmp     edi, 0
        je      .h7id
        cmp     edi, 1
        je      .accept
        cmp     edi, 3
        je      .code
        mov     eax, 1
        ret
.h7id:  mov     eax, 7
        or      eax, 1
        ret
.accept:
        mov     eax, 1
        ret
.code:  mov     eax, 3
        or      eax, 1
        ret

_start:
        ; H7 id
        xor     edi, edi
        call    hostess7
        cmp     eax, 7
        jne     .bad

        ; H7 speak
        mov     edi, 1
        call    hostess7
        cmp     eax, 1
        jne     .bad

        ; self_code shows H7 id
        xor     edi, edi
        call    self_code
        cmp     eax, 7
        jne     .bad

        ; self_code accept
        mov     edi, 1
        call    self_code
        cmp     eax, 1
        jne     .bad

        ; self_code mark
        mov     edi, 3
        call    self_code
        cmp     eax, 3
        jne     .bad

        mov     rax, 1
        mov     rdi, 1
        lea     rsi, [msg_ok]
        mov     rdx, msg_ok_len
        syscall
        mov     rax, 60
        xor     rdi, rdi
        syscall
.bad:
        mov     rax, 1
        mov     rdi, 1
        lea     rsi, [msg_bad]
        mov     rdx, msg_bad_len
        syscall
        mov     rax, 60
        mov     rdi, 2
        syscall

section .rodata
msg_ok: db "OK · Hostess7 inside self_code · codes TRUTH · never ML", 10
msg_ok_len equ $ - msg_ok
msg_bad: db "FAIL · H7 self_code protocol", 10
msg_bad_len equ $ - msg_bad
