Last active
February 8, 2020 04:24
-
-
Save zignig/bcc358d3413e6cd622f5166f7df85304 to your computer and use it in GitHub Desktop.
recursion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @register | |
| class Caller(Firmware): | |
| def instr(self): | |
| w = self.w | |
| w.req(['value','counter']) | |
| ll = LocalLabels() | |
| r = Recurse() | |
| return [ | |
| C('depth',3), | |
| MOVI(w.value,1000), | |
| ll('again'), | |
| MOVI(w.counter,'depth'), | |
| r(w.value,w.counter,ret=[w.value]), | |
| J(ll.again), | |
| ] | |
| FIRMWARE Caller | |
| [ Rem("['value', 'counter', '', '', '', '', 'fp', 'ret']"), | |
| Label('init'), | |
| LDW(R6, 0), | |
| Label('main'), | |
| [ Constant(('depth', 3)), | |
| MOVI(R0, 1000), | |
| Label('again_674161607'), | |
| MOVI(R1, 'depth'), | |
| [ Rem("Load value"), | |
| ST(R0, R6, -8), | |
| Rem("Load counter"), | |
| ST(R1, R6, -7), | |
| JAL(R7, 'Recurse'), | |
| LD(R0, R6, -8)], | |
| J('again_674161607')], | |
| J('main'), | |
| Label('lib_code'), | |
| [ [ [ Label('Recurse'), | |
| Rem("['value', 'counter', '', '', '', '', 'fp', 'ret']"), | |
| ADJW(-8), | |
| LDW(R6, 0), | |
| Rem("decrement the counter, stop @ zero"), | |
| ADDI(R0, R0, 10), | |
| SUBI(R1, R1, 1), | |
| CMPI(R1, 0), | |
| BEQ('exit_200879471'), | |
| [ Rem("Load value"), | |
| ST(R0, R6, -8), | |
| Rem("Load counter"), | |
| ST(R1, R6, -7), | |
| JAL(R7, 'Recurse'), | |
| LD(R0, R6, -8), | |
| LD(R1, R6, -7)], | |
| Label('exit_200879471'), | |
| ADJW(8), | |
| JR(R7, 0)]]], | |
| Label('program_start')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment