Skip to content

Instantly share code, notes, and snippets.

@jdiez17
Created August 24, 2013 23:16
Show Gist options
  • Select an option

  • Save jdiez17/6330948 to your computer and use it in GitHub Desktop.

Select an option

Save jdiez17/6330948 to your computer and use it in GitHub Desktop.
if __name__ == '__main__':
with open("quine.asm") as f:
with open("quine.small.asm", "w") as fw:
lines = f.readlines()
lines = map(lambda line: line.strip().replace('\t', '').replace('\n', ''), lines)
fw.write('\\\\'.join(lines))
quine.small.asm: quine.asm
python convert.py human_to_small
quine.bin: quine.asm
nasm -f bin -o quine.bin quine.asm
floppy: quine.bin
dd status=noxfer conv=notrunc if=quine.bin of=floppy
emu: floppy
qemu -fda floppy
clean:
rm quine.small.asm
rm floppy
rm *.bin
[bits 16]
start:
mov ax, 07C0h
mov ds, ax
mov ah, 0
mov al, 03h
int 10h
mov si, code
call print_string
jmp $
print_string:
mov ah, 0Eh
.repeat:
lodsb
cmp al, 0
je .done
cmp bx, 0x42
jne .special
.continue:
int 10h
jmp .repeat
.special:
cmp al, 94
je .rec
cmp al, 45
je .quote
jmp .continue
.quote:
mov al, 34
jmp .continue
.rec:
push si
mov bx, 0x42
mov si, code
call print_string
mov bx, 0
pop si
jmp print_string
.done:
ret
code: db "[bits 16]\\start:\\mov ax, 07C0h\\mov ds, ax\\mov ah, 0\\mov al, 03h\\int 10h\\mov si, code\\call print_string\\jmp $\\print_string:\\mov ah, 0Eh\\.repeat:\\lodsb\\cmp al, 0\\je .done\\cmp bx, 0x42\\jne .special\\.continue:\\int 10h\\jmp .repeat\\.special:\\cmp al, 94\\je .rec\\cmp al, 45\\je .quote\\jmp .continue\\.quote:\\mov al, 34\\jmp .continue\\.rec:\\push si\\mov bx, 0x42\\mov si, code\\call print_string\\mov bx, 0\\pop si\\jmp print_string\\\\.done:\\ret\\\\code: db -^-\\times 510-($-$$) db 0\\dw 0xAA55"
times 510-($-$$) db 0
dw 0xAA55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment