Post History
x86-64 machine code, 32 bytes A4 FF CA 6A 06 58 F6 F2 50 3C 03 59 51 74 08 AC F3 AA FF CA 75 F5 F3 66 AD 66 F3 AB 58 B0 07 C3 Try it online! Following the standard calling convention for Unix-...
Answer
#1: Initial revision
# x86-64 machine code, 32 bytes A4 FF CA 6A 06 58 F6 F2 50 3C 03 59 51 74 08 AC F3 AA FF CA 75 F5 F3 66 AD 66 F3 AB 58 B0 07 C3 [Try it online!](https://tio.run/##ZVNNj9owFDzHv@I1CK2zhIplKSykVGqr9tZLT5WAQ9Z2iFfBiWLD8iH@eul7DguljSJ/zIzfjF8U0V0KcTqldgUcfoacZZNgVW7sMwukEqDklgXV2uYwTKAqK6hTBKTegCzOhEfEqoK0iOGR1ZPA68QWD3heIP@iwLKgKCUVrlUF1pU3Hi9mD7WnmJ144etViMuLN4bzTiOiHdtPAhaFECVMGwcZF3law32t7LpwMYjSWAcNZmMgSaHM0uVRAptSS9hzPMla2ohiLRV8tE7q8n3@6QaqtVkSxv4u55R1IrXKzhYwhUPY6oVx2PpMQ/8bjYOBB75@p2n8NKZpNBrR1HvoPw4@0OqLf8JjE3@VasMjdmBBVtbACXIGq/cSmt9NYUyLTidiAWqCmzgou0ZyZpGQgKimF7OHoYeuLcADGX9rFL54TyS4iyLSVXhpl/Gw3X2yIfIevKTSTShNmZpquPG58OTake@59Ewvmnpn9G5u7gg4sovF3PxIRa6Nws8l1SQkmky2ZBLDDreyhMObHNq9/i@MtJtyvjZWL42Svgn3URbNtp0OGh7hNdeFgv8V0MG6mPpfYk@uFwve1vC8w35Gc4NWWySPp9NvkRXp0p66q@EAB/xnpqhXxR8 "C (gcc) – Try It Online") Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), takes the address and length of the input string (in ASCII) in RSI and EDX respectively, and writes the output string to an address given in RDI and returns its length in EAX. In assembly: ```` f: movsb # Put the initial '#' from the input string # into the output string, advancing both pointers. dec edx # Subtract 1 from the length in EDX. push 6; pop rax # Set EAX to 6. div dl # Divide AH:AL (EAX's low 2 bytes) by the low byte of EDX. # The quotient goes into AL and the remainder (0) into AX. # EAX now equals the quotient: the number of repetitions. push rax # Save that number onto the stack. cmp al, 3 # Compare AL to 3. r: pop rcx; push rcx # Put the no. of repetitions into RCX from the stack. je s # Jump if AL equaled 3 (special case for 2 digits); # in later iterations, no jump (ZF=0 from the DEC). lodsb # Load a byte from the input string into AL, advancing RSI. rep stosb # Write AL to the output string RCX times, # advancing RDI and counting down RCX to 0. dec edx # Decrease EDX by 1. jnz r # Jump back, to repeat, if it is nonzero. rep # As RCX=0, this prefix makes the following LODSW do nothing. s: lodsw # Load 2 bytes from the input string into AX, advancing RSI. rep stosw # Write AX to the output string RCX times, # advancing RDI and counting down RCX to 0. pop rax # Take the number of repetitions off the stack into RAX. mov al, 7 # Set the low byte of EAX to 7, which makes EAX 7. ret # Return. ````