SMAL32 (rev 9/03) MP2 solved by Douglas Jone 16:36:23 Page 1 Thu Oct 14 2004 10 SUBTITLE Modified Fibonacci Function 65 SUBTITLE Main Program SMAL32 (rev 9/03) MP2 solved by Douglas Jone 16:36:23 Page 2 Thu Oct 14 2004 1 TITLE MP2 solved by Douglas Jones 2 3 S MAIN 4 USE "hawk.macs" 5 USE "monitor.h" +000000:+00000000 6 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 +00000000 7 COMMON STACK,#1000 +000030:+00000000 8 PSTACK: W STACK 9 SMAL32 (rev 9/03) MP2 solved by Douglas Jone 16:36:23 Page 3 Modified Fibonacci Functio Thu Oct 14 2004 10 SUBTITLE Modified Fibonacci Function 11 ; ----------------------------------------------------------------- ; 12 ; Note: This code is based on code from chapter 6 of the notes ; 13 ; It has been heavily modified to conform with the assignment ; 14 ; ----------------------------------------------------------------- ; 15 16 ; activation record format for the F function 17 RA = 0 ; the return address 18 VALUE = 4 ; the tentative unsigned integer return value 19 FS = 8 ; f(S[value]) 20 ARSIZE = 12 ; size of activation record in bytes 21 22 ; the special array S, private to F, required by the assignment 23 ;S: B 0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ; version 1 +000034: 00 00 01 02 24 S: B 0,0,1,2,2,4,3,6,4,8,5,10, 6,12, 7,14, 8 ; version 2 02 04 03 06 04 08 05 0A 06 0C 07 0E 08 25 ALIGN 2 26 27 ; receiving sequence assumptions 28 F: ; R3 holds the unsigned integer parameter i 29 ; R4-5 used as scratch registers 30 ; R6-15 will not be used 31 STORES R1,R2 ; save the return address +000046: F1A2 32 STORE R3,R2,VALUE ; value = i +000048: F322 0004 33 ; note, value is still in R3 34 LEA R4,S +00004C: F470 FFE4 35 ADD R4,R4,R3 +000050: 3443 36 LOADS R5,R4 +000052: F5D4 37 EXTB R3,R5,R4 +000054: 5354 38 BEQ ENDIF ; if (S[value] != 0) { +000056: 0217 39 ; note, S[value] is still in R3 40 ADDI R2,R2,ARSIZE +000058: F262 000C 41 JSR R1,F +00005C: F130 FFE6 42 STORE R3,R2,FS-ARSIZE ; fs = f( S[value] ) +000060: F322 FFFC 43 44 LOAD R3,R2,VALUE-ARSIZE +000064: F352 FFF8 45 ADDSI R3,-1 ; R3 = value - 1 +000068: 13CF 46 LEA R4,S +00006A: F470 FFC6 47 ADD R4,R4,R3 +00006E: 3443 48 LOADS R5,R4 +000070: F5D4 49 EXTB R3,R5,R4 ; R3 = S[value - 1] +000072: 5354 50 JSR R1,F ; R3 = f( S[value - 1] ) +000074: F130 FFCE 51 ADDI R2,R2,-ARSIZE +000078: F262 FFF4 52 ; note, R3 still holds f( S[value - 1] ) 53 LOAD R4,R2,FS +00007C: F452 0008 54 ADD R3,R3,R4 +000080: 3334 55 STORE R3,R2,VALUE ; value = fs + f( S[value - 1] ) +000082: F322 0004 56 57 ENDIF: 58 ; return sequence and assertions 59 LOAD R3,R2,VALUE ; get return value +000086: F352 0004 60 ; R4-5 were used SMAL32 (rev 9/03) MP2 solved by Douglas Jone 16:36:23 Page 4 Modified Fibonacci Functio Thu Oct 14 2004 61 ; R6-15 were not used 62 LOADS R1,R2 ; get the return address +00008A: F1D2 63 JUMPS R1 ; return +00008C: F0B1 64 SMAL32 (rev 9/03) MP2 solved by Douglas Jone 16:36:23 Page 5 Main Program Thu Oct 14 2004 65 SUBTITLE Main Program 66 ; ----------------------------------------------------------------- ; 67 ; Note: This code is a direct translation of C code in mp2.shtml ; 68 ; ----------------------------------------------------------------- ; 69 70 MAIN: LOAD R2,PSTACK ; set up the stack +00008E: F250 FF9E 71 72 LOAD R1,PDSPINI +000092: F150 FF6E 73 JSRS R1,R1 ; dspini(); +000096: F1B1 74 75 LIS R8,0 ; i = 0; +000098: D800 76 77 MAILP: ; do { 78 MOVE R3,R8 +00009A: F3F8 79 LIS R4,1 +00009C: D401 80 LOAD R1,PDSPDECU +00009E: F150 FF7A 81 JSRS R1,R1 ; dspdecu( i, 1 ); +0000A2: F1B1 82 83 LIS R3,':' +0000A4: D33A 84 LOAD R1,PDSPCH +0000A6: F150 FF62 85 JSRS R1,R1 ; dspch( ':' ); +0000AA: F1B1 86 87 MOVE R3,R8 +0000AC: F3F8 88 JSR R1,F +0000AE: F130 FF94 89 LIS R4,1 +0000B2: D401 90 LOAD R1,PDSPDECU +0000B4: F150 FF64 91 JSRS R1,R1 ; dspdecu( f(i), 1 ); +0000B8: F1B1 92 93 LIS R3,' ' +0000BA: D320 94 LOAD R1,PDSPCH +0000BC: F150 FF4C 95 JSRS R1,R1 ; dspch( ' ' ); +0000C0: F1B1 96 97 ADDSI R8,1 ; i++; +0000C2: 18C1 98 99 CMPI R8,16 +0000C4: F068 FFF0 100 BLT MAILP ; } while (i < 16); +0000C8: 05E8 101 102 LOAD R1,PEXIT +0000CA: F150 FF32 103 JSRS R1,R1 ; exit(); +0000CE: F1B1 104 105 END no errors