46 lines
858 B
NASM
46 lines
858 B
NASM
; strlen
|
|
bits 64
|
|
|
|
SECTION .data
|
|
mystr: db 't','e','s','t',0
|
|
|
|
SECTION .text
|
|
|
|
global _start
|
|
_start:
|
|
%include "header.asm.inc"
|
|
|
|
mov rcx, 0
|
|
xor rbx, rbx
|
|
repnz sub rbx, 1
|
|
|
|
; get reference to string
|
|
mov rdi, mystr
|
|
|
|
; move MAXINT to rcx
|
|
xor rcx, rcx
|
|
not rcx
|
|
|
|
; zero al
|
|
xor al, al
|
|
|
|
cld ; clear direction flag -->
|
|
; increment addresses during string search
|
|
|
|
; repne: perform <instr> (scasb) and repeat if <cond> (ne) is met
|
|
; decrements rcx and aborts if rcx == 0
|
|
; scasb: compare byte at rdi with al and set flags; increment rdi
|
|
repne scasb
|
|
|
|
; option 1: current string index minus string start minus one
|
|
mov rax, rdi
|
|
sub rax, mystr
|
|
dec rax
|
|
|
|
; option 2: look at counter modified by repne (rcx)
|
|
not rcx
|
|
dec rcx
|
|
|
|
%include "sysexit.asm.inc"
|
|
|