r/badcode • • Dec 17 '20

[deleted by user]

[removed]

26 Upvotes

21 comments sorted by

View all comments

5

u/binarycat64 Dec 23 '20 edited Dec 27 '20

Fibonocci numbers:

#!/usr/bin/ruby
`tail #$0 -n 13 > asdf.asm`
`nasm -felf64 asdf.asm`
`ld asdf.o`
r=""
while r.length < ARGV[0].to_i
  puts `echo -n #{r} | fish -c './a.out; echo $status'`
  r<<'1'
end
__END__
	section .text
	global _start
_start:	and rax, 0h
	imul rdi, 0o
	mov rsi, buff
	mov rdx, 1110b
	syscall
        sub dil, dil
	mov byte dil, byte [rax+buff]
	mov rax, 111100b
	syscall	
	section .data
buff:	db 1,1,2,3,5,8,13,21,34,55,89,144,233

Features:

  • reassembly each time
  • overwriting a number of files in the current directory
  • not deleting those files
  • asm input is in unary
  • asm output is exit status
  • "precomputing"
  • because of the last 2, doesn't work for long
  • never use the same method of zeroing a register twice
  • random base suffixes
  • reading from the source file
  • sub-sub-shells
  • fish dependency
  • I'm not even sure how it works

1

u/AutoModerator Dec 23 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/binarycat64, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/AutoModerator Dec 27 '20

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/binarycat64, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.