Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Expand a greyscale/colour hex code

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-...

posted 1mo ago by m90‭

Answer
#1: Initial revision by user avatar m90‭ · 2025-01-22T16:58:39Z (about 1 month ago)
# 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.
````