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 8 coexisting queens

x86-64 machine code, 27 bytes 6A D7 58 99 B1 10 48 D3 C0 48 AB C6 07 0A AE 80 C1 48 73 F2 FF C2 74 EC 88 37 C3 Try it online! Following the standard calling convention for Unix-like systems (f...

posted 2y ago by m90‭  ·  edited 2y ago by m90‭

Answer
#2: Post edited by user avatar m90‭ · 2023-02-17T09:23:04Z (almost 2 years ago)
Correction in explanation
  • # x86-64 machine code, 27 bytes
  • 6A D7 58 99 B1 10 48 D3 C0 48 AB C6 07 0A AE 80 C1 48 73 F2 FF C2 74 EC 88 37 C3
  • [Try it online!](https://tio.run/##TZHBTgIxEIbPnacY1xC7upBF0QOIB41HE2M8aIBDabtsTWmhXXCR@Oqug0j00DYz/z/fzKSyPZOyaUScI8enhENnZv1UWCyg6LPFKpbY7nUHuPALDKIGJtUSQq/P5n6N0maYT/M879LJIfRZ8HZny0gCFisfl/DjvH19vsfH5yccBWUmGZ6M3QkZpIhTYEKpA6q7ZwF7cxIDMEOPVtT27QNDb8/6RagSWNAVpAmmA1h7o7DgshThFCMl4Jhq7UppvI6VMr5T3gAYV@FcGMdT2NIqZMag48pWo8vu@WQArOD7mABsEche8KQVkwz/0n/C2D0IWRqnUXql@8lO3XWocYh5hhsKlcftwY6t/PyFUJsh5ysXzcxp2ns3cFqko/rsbJIOPvG9NFYj3@ARQeq7i/@TIG8ZnG4qHdOxI1JN4mfTfMnCills2vOrHl30l0Pya/sN "C (gcc) – Try It Online")
  • Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI a memory address at which to place the result, as a null-terminated byte string in [ISO-8859-1](https://en.wikipedia.org/wiki/ISO-8859-1).
  • In assembly:
  • ````
  • f: push -41; pop rax # Set RAX to -41: low byte 0xD7, other bytes 0xFF.
  • cdq # Set EDX to -1 by sign-extending EAX.
  • r4: mov cl, 0b00010000 # Set CL to 2*8.
  • r: rol rax, cl # Rotate RAX left by the value of CL.
  • # CL will always be a multiple of 8; this moves the 0xD7 byte.
  • stosq # Write RAX to the string, advancing the pointer.
  • mov [rdi], '\n' # Add a line feed to the string.
  • scasb # Advance past it while comparing it with AL.
  • add cl, 0b01001000 # Add 1*8+64 to CL.
  • jnc r # Jump if no carry; iterate 4 times.
  • inc edx # Add 1 to EDX.
  • jz r4 # Jump (here resetting CL) if it's 0.
  • mov [rdi], dl # Add a 0 byte from DL to the string.
  • ret # Return.
  • ````
  • The output is:
  • ````
  • ÿÿ×ÿÿÿÿÿ
  • ÿÿÿÿÿ×ÿÿ
  • ÿ×ÿÿÿÿÿÿ
  • ÿÿÿÿÿÿ×ÿ
  • ×ÿÿÿÿÿÿÿ
  • ÿÿÿ×ÿÿÿÿ
  • ÿÿÿÿÿÿÿ×
  • ÿÿÿÿ×ÿÿÿ
  • ````
  • This solution was chosen for the pattern formed by the horizontal offsets between queen positions in adjacent rows, wrapping around and starting at 0; those offsets are 2, 3, 4, 5, 2, 3, 4, 5.
  • # x86-64 machine code, 27 bytes
  • 6A D7 58 99 B1 10 48 D3 C0 48 AB C6 07 0A AE 80 C1 48 73 F2 FF C2 74 EC 88 37 C3
  • [Try it online!](https://tio.run/##TZHBTgIxEIbPnacY1xC7upBF0QOIB41HE2M8aIBDabtsTWmhXXCR@Oqug0j00DYz/z/fzKSyPZOyaUScI8enhENnZv1UWCyg6LPFKpbY7nUHuPALDKIGJtUSQq/P5n6N0maYT/M879LJIfRZ8HZny0gCFisfl/DjvH19vsfH5yccBWUmGZ6M3QkZpIhTYEKpA6q7ZwF7cxIDMEOPVtT27QNDb8/6RagSWNAVpAmmA1h7o7DgshThFCMl4Jhq7UppvI6VMr5T3gAYV@FcGMdT2NIqZMag48pWo8vu@WQArOD7mABsEche8KQVkwz/0n/C2D0IWRqnUXql@8lO3XWocYh5hhsKlcftwY6t/PyFUJsh5ysXzcxp2ns3cFqko/rsbJIOPvG9NFYj3@ARQeq7i/@TIG8ZnG4qHdOxI1JN4mfTfMnCills2vOrHl30l0Pya/sN "C (gcc) – Try It Online")
  • Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI a memory address at which to place the result, as a null-terminated byte string in [ISO-8859-1](https://en.wikipedia.org/wiki/ISO-8859-1).
  • In assembly:
  • ````
  • f: push -41; pop rax # Set RAX to -41: low byte 0xD7, other bytes 0xFF.
  • cdq # Set EDX to -1 by sign-extending EAX.
  • r4: mov cl, 0b00010000 # Set CL to 2*8.
  • r: rol rax, cl # Rotate RAX left by the value of CL.
  • # CL will always be a multiple of 8; this moves the 0xD7 byte.
  • stosq # Write RAX to the string, advancing the pointer.
  • mov [rdi], '\n' # Add a line feed to the string.
  • scasb # Advance past it while comparing it with AL.
  • add cl, 0b01001000 # Add 1*8+64 to CL.
  • jnc r # Jump if no carry; iterate 4 times.
  • inc edx # Add 1 to EDX.
  • jz r4 # Jump (here resetting CL) if it's 0.
  • mov [rdi], dh # Add a 0 byte from DH to the string.
  • ret # Return.
  • ````
  • The output is:
  • ````
  • ÿÿ×ÿÿÿÿÿ
  • ÿÿÿÿÿ×ÿÿ
  • ÿ×ÿÿÿÿÿÿ
  • ÿÿÿÿÿÿ×ÿ
  • ×ÿÿÿÿÿÿÿ
  • ÿÿÿ×ÿÿÿÿ
  • ÿÿÿÿÿÿÿ×
  • ÿÿÿÿ×ÿÿÿ
  • ````
  • This solution was chosen for the pattern formed by the horizontal offsets between queen positions in adjacent rows, wrapping around and starting at 0; those offsets are 2, 3, 4, 5, 2, 3, 4, 5.
#1: Initial revision by user avatar m90‭ · 2022-10-01T16:32:48Z (about 2 years ago)
# x86-64 machine code, 27 bytes
    6A D7 58 99 B1 10 48 D3 C0 48 AB C6 07 0A AE 80 C1 48 73 F2 FF C2 74 EC 88 37 C3
[Try it online!](https://tio.run/##TZHBTgIxEIbPnacY1xC7upBF0QOIB41HE2M8aIBDabtsTWmhXXCR@Oqug0j00DYz/z/fzKSyPZOyaUScI8enhENnZv1UWCyg6LPFKpbY7nUHuPALDKIGJtUSQq/P5n6N0maYT/M879LJIfRZ8HZny0gCFisfl/DjvH19vsfH5yccBWUmGZ6M3QkZpIhTYEKpA6q7ZwF7cxIDMEOPVtT27QNDb8/6RagSWNAVpAmmA1h7o7DgshThFCMl4Jhq7UppvI6VMr5T3gAYV@FcGMdT2NIqZMag48pWo8vu@WQArOD7mABsEche8KQVkwz/0n/C2D0IWRqnUXql@8lO3XWocYh5hhsKlcftwY6t/PyFUJsh5ysXzcxp2ns3cFqko/rsbJIOPvG9NFYj3@ARQeq7i/@TIG8ZnG4qHdOxI1JN4mfTfMnCills2vOrHl30l0Pya/sN "C (gcc) – Try It Online")

Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI a memory address at which to place the result, as a null-terminated byte string in [ISO-8859-1](https://en.wikipedia.org/wiki/ISO-8859-1).

In assembly:
````
f:	push -41; pop rax   # Set RAX to -41: low byte 0xD7, other bytes 0xFF.
	cdq                 # Set EDX to -1 by sign-extending EAX.
r4:	mov cl, 0b00010000  # Set CL to 2*8.
r:	rol rax, cl         # Rotate RAX left by the value of CL.
	    # CL will always be a multiple of 8; this moves the 0xD7 byte.
	stosq               # Write RAX to the string, advancing the pointer.
	mov [rdi], '\n'     # Add a line feed to the string.
	scasb               # Advance past it while comparing it with AL.
	add cl, 0b01001000  # Add 1*8+64 to CL.
	jnc r               # Jump if no carry; iterate 4 times.
	inc edx             # Add 1 to EDX.
	jz r4               # Jump (here resetting CL) if it's 0.
	mov [rdi], dl       # Add a 0 byte from DL to the string.
	ret                 # Return.
````

The output is:
````
ÿÿ×ÿÿÿÿÿ
ÿÿÿÿÿ×ÿÿ
ÿ×ÿÿÿÿÿÿ
ÿÿÿÿÿÿ×ÿ
×ÿÿÿÿÿÿÿ
ÿÿÿ×ÿÿÿÿ
ÿÿÿÿÿÿÿ×
ÿÿÿÿ×ÿÿÿ
````

This solution was chosen for the pattern formed by the horizontal offsets between queen positions in adjacent rows, wrapping around and starting at 0; those offsets are 2, 3, 4, 5, 2, 3, 4, 5.