Created
November 30, 2009 01:57
-
-
Save burke/245215 to your computer and use it in GitHub Desktop.
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
| ;;; File: fibonacci.asm | |
| ;;; Author: Burke Libbey <[email protected]> | |
| ;;; Modified: <2009-11-29 19:26:28 CST> | |
| ;;; | |
| ;;; Generates Fibonacci numbers on hard drive | |
| MOVE R10,0 ; HD Status | |
| MOVE R11,1 ; HD Addr Reg | |
| MOVE R12,2 ; HD MAR | |
| MOVE R13,3 ; First real memory loc. | |
| MOVE R14,4 ; Second memory loc. | |
| ;; First, put the initial condition in memory. | |
| MOVE [R13],R11 ; Set mem[3] to 1 | |
| MOVE [R14],R11 ; Set mem[4] to 1 | |
| ;; Copy initial conditions for fibs to the HDD. | |
| MOVE [R11],R10 ; Use HD Address 0 | |
| MOVE [R12],R13 ; Use memory address 3 | |
| MOVE [R10],R13 ; Write one word to HDD | |
| MOVE [R11],R11 ; Now use HD Address 1 | |
| MOVE [R12],R14 ; Use memory address 3 | |
| MOVE [R10],R13 ; And write another word. | |
| ;; We now have 1 1 on the HDD. From here, we'll generate | |
| ;; the fibonacci numbers iteratively, storing them to the | |
| ;; drive as we go. | |
| MOVE R0,2 ; HD Address of the next number to generate | |
| MOVE R8,24 ; Maximum HD Address to generate number for | |
| ;; So mem[3] and mem[4] contain the last numbers. | |
| ;; Set mem[3] to mem[4] and mem[4] to mem[3]+mem[4], | |
| ;; Then write the new mem[4] to the hard drive. | |
| loop: MOVE R3,[R13] | |
| MOVE R4,[R14] | |
| ADD R3,R4 ; New number | |
| MOVE [R13],R4 | |
| MOVE [R14],R3 | |
| ;; So mem[3] and mem[4] contain the most recent tail of the seq. | |
| ;; We need to update the HDD with mem[4]. | |
| MOVE [R11],R0 ; Use next open HDD addr | |
| MOVE [R12],R14 ; Use mem[4]. | |
| MOVE [R10],R13 ; Write one word | |
| ADD R0,1 ; Set the next address to write a number to | |
| BGT R8,loop ; If we're not done yet, keep going... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment