Skip to content

Instantly share code, notes, and snippets.

@5310
Created February 10, 2013 07:53
Show Gist options
  • Save 5310/4748840 to your computer and use it in GitHub Desktop.
Save 5310/4748840 to your computer and use it in GitHub Desktop.
A brainfuck routine to print an integer as ascii, in minified and commented form. Needs two zeroed pointers following the value to be printed. Currently only prints single digit integers. Will fix later, but would need more pointers to work on, which makes me uncomfortable.
RESET
;; print integer as ascii ;;
;; put value on o0 ;;
;; needs o1~2 zeroed ;;
;; leaves o1~2 zeroed ;;
>>++++++++[<++++++>-]<<[>>+<<-]>>[<<+ >+>-]<.[-]<
RESET
;; test and explanation ;;
;; p0v5 to be printed
+++++.
;; print positive number as ascii ;;
;; put positive value on o0 ;;
;; needs o1~2 zeroed ;;
;; leaves o1~2 zeroed ;;
; ascii 0 = o1v48
>>
++++++++
[
<++++++
>-
]
<
; copy o0 to o2
<
[
>>+ ; o2/
<<- ; o0\
]
; copy o2 to o0 and add to o1
>>
[
<<+ ; o0/
>+ ; o1/
>- ; o2\
]
; print ascii value from o1
<.
clear o1
[-]
; move to o0
<
;; end code ;;
@5310
Copy link
Author

5310 commented Feb 10, 2013

Comments use a variation of the shorthand used by Nieko Maatjes on his tutorial.

Here, pX is pointer number X, vX is value X, the addition, oX means pointer X places offset from current.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment