Skip to content

Instantly share code, notes, and snippets.

@dasmithii
Last active July 9, 2018 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasmithii/9586834 to your computer and use it in GitHub Desktop.
Save dasmithii/9586834 to your computer and use it in GitHub Desktop.
Implementation of unsigned integer addition in Brainfuck. Assumes pointer placement to be at byte zero, and the following eight bytes to represent two four-byte integers.
=====================================================================================================
=====================================================================================================
===================================| Perform Addition: |========================================
=====================================================================================================
=====================================================================================================
FOR EACH UNIT IN BYTE 5:
>>>>[-<<<<
INCREMENT BYTE 1:
+ B1
[->>>>>>>>+>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<<+>>>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<<[-]> B2
+ B2
[->>>>>>>+>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<[-]> B3
+ B3
[->>>>>>+>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<[-]>+ B4
[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<<[-]>[-]>[-]>[-]>>>>>>] B10
]
]
]
<<<<<<<<<
>>>>]
FOR EACH UNIT IN BYTE 6:
>[-<<<<<
INCREMENT BYTE 2:
>+ B2
[->>>>>>>+>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<[-]> B3
+ B3
[->>>>>>+>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<[-]>+ B4
[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<<[-]>[-]>[-]>[-]>>>>>>] B10
]
] B10
<<<<<<<<<
>>>>>]
FOR EACH UNIT IN BYTE 7
>[-<<<<<<
>>+ B3
[->>>>>>+>+<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<[-]>+ B4
[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<<[-]>[-]>[-]>[-]>>>>>>] B10
] B10
<<<<<<<<<
>>>>>>]
FOR EACH UNIT IN BYTE 8
>[-<<<<<<<
>>>+ B4
[->>>>>+>+<<<<<<]>>>>>>[-<<<<<<+>>>>>>] B10
+<[- >[-]<]>[- <<<<<<<<<[-]>[-]>[-]>[-]>>>>>>] B10
<<<<<<<<<
>>>>>>>]
RETURN POINTER TO ORIGIN
<<<<<<<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment