Post History
x86-64 machine code, 36 bytes 31 C0 8D 48 0A FF C0 50 99 89 17 48 F7 F1 01 17 99 85 C0 75 F6 58 50 F7 37 58 85 D2 75 E7 AB FF CE 75 E2 C3 Try it online! Following the standard calling conventi...
Answer
#1: Initial revision
# x86-64 machine code, 36 bytes 31 C0 8D 48 0A FF C0 50 99 89 17 48 F7 F1 01 17 99 85 C0 75 F6 58 50 F7 37 58 85 D2 75 E7 AB FF CE 75 E2 C3 [Try it online!](https://tio.run/##TZLBTuMwEIbP8VMMWSHZJKDSIg7tlgtcV4sqpEVqezC203jl2sFOuy5VX53smFDoxfbM/P83k1FE01yuhOg6HtZAYZZTcrUy7oUbqEg1zqLzoHgs00EyozgogdHc81hcD5bEjDNtRV9tNqEGn15CvpJs7baok3qJZhmJRqnUW/ACBVzK01pvaFVoT5r9tW@gDWJd01O/@Ynz8Of37AEen2Y96ETXc2T8ZCcOYkLrgkSrwmmD/kp71RKWA5sQFVvlLeT3Oey3TkuoqLYtXPgS0h3Z5EDID/xas5EKfoZWandV3xGSqmuuLWVkT7IPLUxhUMIuXZM@5VXYmHY@Gi4xUdE@LGE0ZCnGLdNejaazKabxURSMZFnj0V7R/FxDXh4xu2WyHUsLu7C/uKi1VSCcVOM8VeNnd@lgf1TC@WD4jJjdlNKNDXpllQRRc3/BKjaPRYHcA/yrtVFpIJxkEO9Hp72A4iAvO9wxW1gk4VrIoeveRWX4KnSX69sbPPBvmqJemf8 "C++ (gcc) – Try It Online") Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI an address of an array of `n` 32-bit integers to be filled in with the Nuven numbers, and takes `n` in ESI. In assembly: ```` f: xor eax, eax # Set EAX to 0. EAX will hold the currently tried number. lea ecx, [rax+10] # Set ECX to 10. l: inc eax # Increase EAX by 1. push rax # Push RAX (64-bit register containing EAX) onto the stack. cdq # Sign-extend, making EDX 0 provided EAX hasn't overflowed. mov [rdi], edx # Place 0 at address RDI. il: div rcx # Divide EDX:EAX (equal to EAX, as EDX is 0) by 10. # The quotient goes in EAX and the remainder goes in EDX. add [rdi], edx # Add the remainder to the value at address RDI. cdq # Sign-extend, making EDX 0 provided EAX hasn't overflowed. test eax, eax # Check the value in EAX. jnz il # Jump back, to repeat the division loop, if it's nonzero. pop rax # Restore the value of RAX from the stack. push rax # Push it onto the stack again. div DWORD PTR [rdi] # Divide EDX:EAX (equal to EAX, as EDX is 0) by # the value at address RDI, which is the digit sum. # The quotient goes in EAX and the remainder goes in EDX. pop rax # Restore the value of RAX from the stack. test edx, edx # Check the value of the remainder in EDX. jnz l # Jump back, repeating the outer loop, if it's nonzero. # (Otherwise, the value in EAX is a Niven number.) stosd # Put EAX's value at address RDI, advancing the pointer. dec rsi # Subtract 1, counting down from the input number in ESI. jnz l # Jump back, repeating the outer loop, if it's nonzero. ret # Return. ````