Created
November 22, 2011 20:54
-
-
Save dflemstr/1386925 to your computer and use it in GitHub Desktop.
INDA11 HT9
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
| ; Produces the fibonacci series in memory. | |
| ;.rodata | |
| word count 11 | |
| ;.data | |
| word result0 1 | |
| word result1 1 | |
| word result 0 | |
| ;let: | |
| ;r0: constant 0 | |
| ;r1: running fibonacci param 1 | |
| ;r2: running fibonacci param 2 | |
| ;r3: running fibonacci value | |
| ;r4: current result location | |
| ;r5: number of remaining numbers | |
| ;.text | |
| load r1 result0 | |
| load r2 result1 | |
| loadc r4 result | |
| load r5 count ; Number of non-trivial numbers to compute | |
| l0: add r3 r2 r1 ; Calculate next number | |
| move r2 r1 ; Use param 2 as param 1 | |
| move r3 r2 ; Use next number as param 2 | |
| storer r3 r4 ; Save the number | |
| addc r4 2 ; Incr number index | |
| addc r5 -1 ; Decr rem counter | |
| jumpn r5 l0 ; Term if rem is 0 |
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
| ; Produces the fibonacci series in memory. | |
| ;.rodata | |
| ;.data | |
| ;let: | |
| ;r0: constant 0 | |
| ;r1: running fibonacci param 1 | |
| ;r2: running fibonacci param 2 | |
| ;r3: current mem location | |
| ;.text | |
| loadc r1 1 | |
| loadc r3 0xE8 | |
| l0: add r1 r1 r2 | |
| add r2 r2 r1 | |
| storer r1 r3 | |
| addc r3 2 | |
| jumpn r3 l0 |
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
| ; Moves the word 0xff around in an interesting pattern. | |
| ; The pattern is determined by using a simple | |
| ; pseudo random number generator (prng). | |
| ;let: | |
| ;r0: current 0xff location | |
| ;r1: prng factor | |
| ;r2: prng offset | |
| ;r3: cur prng value (initially 0) | |
| ;r4: constant 0xff | |
| ;r5: constant 0x00 | |
| ;r6: constant 2 | |
| ;.text | |
| loadc r0 0x80 | |
| loadc r1 0xf5 ; Random value | |
| loadc r2 0x7e ; Random value | |
| loadc r4 0xff | |
| loadc r6 2 | |
| storer r4 r0 ; Set *0x80 to 0xff | |
| l0: mul r3 r3 r1 ; Scramble prng with factor | |
| add r3 r3 r2 ; Scramble prng with offset | |
| storer r5 r0 ; Clear current cell | |
| move r3 r0 ; Set rnd value as cur cell loc | |
| shift r0 r0 r6 ; Div by 4 (Don't just div by 2 since we... ) | |
| shift r0 r0 r4 ; Mul by 2 (...need to page-align the address) | |
| addc r0 0x80 ; r0 is now between 0x80 and 0xff | |
| storer r4 r0 ; Fill current cell | |
| jump l0 ; Optional break condition: jumpn r4 l0 |
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
| ; Multiplies every element in the array v by a factor | |
| ;.rodata | |
| word factor 2 | |
| word v_size 8 | |
| ;.data | |
| word v 1 2 3 4 5 6 7 8 | |
| ;let: | |
| ;r0: constant 0 | |
| ;r1: current elem location | |
| ;r2: number of remaining elems | |
| ;r3: the factor to multiply by | |
| ;r4: temp | |
| ;.text | |
| loadc r1 v | |
| load r2 v_size | |
| load r3 factor | |
| l0: loadr r4 r1 ; Load cur elem | |
| mul r4 r4 r3 ; Mul cur elem by factor | |
| storer r4 r1 ; Store cur elem | |
| addc r1 2 ; Incr array index | |
| addc r2 -1 ; Decr rem counter | |
| jumpn r2 l0 ; Term if rem is 0 (r0 is intialized to 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment