# Peasantmultiplication: # %rdi and %rsi to be multiplied and return result in %rax # INPUT %rdi and %rsi # OUTPUT %rax # Other internal register: r8 and r9 multiply: # Rax to zero irmovq $0, %rax # r8 is place for the bit mask irmovq $1, %r8 # Bitmask in r8 is compared against parameter in rsi, rdi is bit shifted and added to sum depending about comparison pmloop: # In this loop: # Check if each bit from right to left is 1 # If yes, then add rdi to rax # r9 helps to store comparison result temporally rrmovq %r8, %r9 # Get single bit with mask andq %rsi, %r9 # Check if result is equal to mask subq %r8, %r9 # If zero, continue to next round jne pmloopzero # Add current number to end sum if bit was 1 and continue normally addq %rdi, %rax pmloopzero: # Left bit shift to number rdi and mask r8 addq %rdi, %rdi addq %r8, %r8 # Check ending condition rdi has overflowed to negative side # Use r9 as temporal comparison register irmovq $0, %r9 addq %r8, %r9 jle pmend jmp pmloop pmend: ret