Files
pplus-web/quarto/example/programs/two-pointers.asm
T
2026-10-05 03:03:38 +00:00

28 lines
739 B
NASM

; rdi = list A rsi = |A| rdx = list B rcx = |B|
; rax = how many values appear in both
xor eax, eax
xor r8, r8
xor r9, r9
.step:
cmp r8, rsi
jae .done
cmp r9, rcx
jae .done
mov r10, qword ptr [rdi + r8*8]
mov r11, qword ptr [rdx + r9*8]
cmp r10, r11
je .both
jb .advanceA
add r9, 1 ; the second list is behind
jmp .step
.advanceA:
add r8, 1 ; the first list is behind
jmp .step
.both:
add rax, 1
add r8, 1
add r9, 1
jmp .step
.done:
ret