Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions archive/x/x86-64/quine.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
; SYSCALLS
%DEFINE SYS_READ 0
%DEFINE SYS_WRITE 1
%DEFINE STDOUT 1
%DEFINE SYS_EXIT 60
section .data
string:
.msg db "; SYSCALLS%DEFINE SYS_READ 0%DEFINE SYS_WRITE 1%DEFINE STDOUT 1%DEFINE SYS_EXIT 60section .datastring:.msg db .len equ $- .msgquote db 0x22newline db 0xAlinestarts dw 0, 10, 18, 19, 16, 19, 13, 7, 8linestarts2 dw 16, 13, 14, 45, 312, 17, 13, 13, 7, 19, 10, 11, 12, 6, 12, 18, 15, 12, 31, 24, 7, 12, 12, 8, 18, 15, 16, 10, 7, 12, 10, 12, 9, 6, 18, 15, 14, 10, 7, 18, 15, 19, 19, 7, 18, 15, 14, 10, 7, 18, 15, 16, 10, 7, 10, 6, 12, 18, 15, 12, 32, 25, 7, 12, 12, 8, 18, 15, 16, 10, 7, 12, 10, 12, 9, 6, 11, 10, 7%DEFINE PRINT1 90section .textglobal _start_start:MOV R12, string.msgMOV R13, 2MOV R14, 16MOV R15, 158loop0:MOV RCX, R13MOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, R12ADD R12W, WORD [linestarts+RCX]MOV DX, [linestarts+RCX]SYSCALLMOV RCX, R13CMP RCX, R14JE exit1MOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, newlineMOV RDX, 1SYSCALLMOV RCX, R13ADD RCX, 2MOV R13, RCXJMP loop0exit1:MOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, quoteMOV RDX, 1SYSCALLMOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, string.msgMOV RDX, string.lenSYSCALLMOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, quoteMOV RDX, 1SYSCALLMOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, newlineMOV RDX, 1SYSCALLMOV R13, 0loop1:MOV RCX, R13MOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, R12ADD R12W, WORD [linestarts2+RCX]MOV DX, [linestarts2+RCX]SYSCALLMOV RCX, R13CMP RCX, R15JE exit2MOV RAX, SYS_WRITEMOV RDI, STDOUTMOV RSI, newlineMOV RDX, 1SYSCALLMOV RCX, R13ADD RCX, 2MOV R13, RCXJMP loop1exit2:MOV RAX, 60MOV RDI, 0SYSCALL"
.len equ $- .msg
quote db 0x22
newline db 0xA
linestarts dw 0, 10, 18, 19, 16, 19, 13, 7, 8
linestarts2 dw 16, 13, 14, 45, 312, 17, 13, 13, 7, 19, 10, 11, 12, 6, 12, 18, 15, 12, 31, 24, 7, 12, 12, 8, 18, 15, 16, 10, 7, 12, 10, 12, 9, 6, 18, 15, 14, 10, 7, 18, 15, 19, 19, 7, 18, 15, 14, 10, 7, 18, 15, 16, 10, 7, 10, 6, 12, 18, 15, 12, 32, 25, 7, 12, 12, 8, 18, 15, 16, 10, 7, 12, 10, 12, 9, 6, 11, 10, 7
%DEFINE PRINT1 90
section .text
global _start
_start:
MOV R12, string.msg
MOV R13, 2
MOV R14, 16
MOV R15, 158
loop0:
MOV RCX, R13
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, R12
ADD R12W, WORD [linestarts+RCX]
MOV DX, [linestarts+RCX]
SYSCALL
MOV RCX, R13
CMP RCX, R14
JE exit1
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, newline
MOV RDX, 1
SYSCALL
MOV RCX, R13
ADD RCX, 2
MOV R13, RCX
JMP loop0
exit1:
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, quote
MOV RDX, 1
SYSCALL
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, string.msg
MOV RDX, string.len
SYSCALL
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, quote
MOV RDX, 1
SYSCALL
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, newline
MOV RDX, 1
SYSCALL
MOV R13, 0
loop1:
MOV RCX, R13
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, R12
ADD R12W, WORD [linestarts2+RCX]
MOV DX, [linestarts2+RCX]
SYSCALL
MOV RCX, R13
CMP RCX, R15
JE exit2
MOV RAX, SYS_WRITE
MOV RDI, STDOUT
MOV RSI, newline
MOV RDX, 1
SYSCALL
MOV RCX, R13
ADD RCX, 2
MOV R13, RCX
JMP loop1
exit2:
MOV RAX, 60
MOV RDI, 0
SYSCALL