TITLE "mp6test.a by Douglas Jones -- test program for mp6" USE "hawk.h" USE "stdio.h" USE "ascii.h" USE "stdlib.h" USE "float.h" EXT FTOINT ; FTOINT is defined in mp6.a INT MAIN ; this is a main program S MAIN ; activaiton record for main ;RETAD = 0 ARSIZE = 4 MAIN: ; expects nothing ; returns nothing ; uses R8 = i -- loop counter ; uses R9 = (float)i STORES R1,R2 ADDSI R2,ARSIZE LEA R3,FIRST LIL R1,PUTSTR JSRS R1,R1 ; putstr( " First try numbers:\n" ) LIF R3,2.0E9 LIW R4,2000000000 JSR R1,TRY ; try( 2.0E9, 0 ) LIW R8,1000000000 ; i = 1,000,000,000 MAINLP: TESTR R8 BEQ ENDLP ; while (i > 0) { LIL R1,FPENAB+FPSEL+FPSHORT COSET R1,COSTAT COSET R8,FPINT+FPA0 COGET R9,FPA0 ; -- compute (float)i COSET R0,COSTAT MOVE R3,R9 ; -- parameter (float)i -- value to convert MOVE R4,R8 ; -- parameter i -- expected result JSR R1,TRY ; try( (float)i, i ) SUB R3,R3,R3 ; -- set carry bit MOVE R3,R9 ADJUST R3,CMSB ; -- parameter -(float)i NEG R4,R8 ; -- parameter -i JSR R1,TRY ; try( -(float)i, -i ) MOVE R3,R8 ; -- parameter i LIS R4,10 ; -- parameter 10 LIL R1,DIVIDEU JSRS R1,R1 MOVE R8,R3 ; i = i / 10 BR MAINLP ENDLP: ; } LEA R3,SECOND LIL R1,PUTSTR JSRS R1,R1 ; putstr( " Then try under and overflow:\n" ) LIF R3,0.99 LIL R4,0 JSR R1,TRY ; try( 0.99, 0 ) LIF R3,-0.99 LIL R4,0 JSR R1,TRY ; try( -0.99, 0 ) LIF R3,3.0E9 LIW R4,#80000000 JSR R1,TRY ; try( 3.0E9, 0x80000000 ) LIF R3,-3.0E9 LIW R4,#80000000 JSR R1,TRY ; try( 3.0E9, 0x80000000 ) ADDSI R2,-ARSIZE LOADS PC,R2 ; return FIRST: ASCII " First try numbers:",LF,0 SECOND: ASCII " Then try under and overflow:",LF,0 ALIGN 2 ; activation record for try ;RETAD = 0 R8SV = 4 R9SV = 8 R10SV = 12 R11SV = 16 R12SV = 20 R13SV = 24 R14SV = 28 R15SV = 32 I = 36 ARSIZE = 40 TRY: ; expects R3 = f -- floating value to convert ; R4 = i -- expected integer value ; uses R8-R15 as guards to check calling sequence conformance ; R8 = guardsum -- sum of guards values (-8 if guards OK) ; R9 = i -- sometimes ; R10 = test -- difference twixt expected and actual result STORES R1,R2 STORE R8,R2,R8SV STORE R9,R2,R9SV STORE R10,R2,R10SV STORE R11,R2,R11SV STORE R12,R2,R12SV STORE R13,R2,R13SV STORE R14,R2,R14SV STORE R15,R2,R15SV ; --R8-15 saved; allows test of calling rules ADDI R2,R2,ARSIZE STORE R4,R2,I-ARSIZE ; -- save parameter i LIS R8,-1 ; -- set guard values in R8-15 LIS R9,-1 LIS R10,-1 ; these guard values allow LIS R11,-1 ; the code to detect violation LIS R12,-1 ; of calling conventions by LIS R13,-1 ; solutions to MP6 LIS R14,-1 LIS R15,-1 ; -- R8-R15 all -1 ; -- parameter f already in R3 LIL R1,FTOINT JSRS R1,R1 ; j = ftoint( f ) ADD R8,R8,R9 ; -- check guard values in R8-15 ADD R8,R8,R10 ADD R8,R8,R11 ADD R8,R8,R12 ADD R8,R8,R13 ADD R8,R8,R14 ADD R8,R8,R15 ; -- R8 holds guardsum, should be -8 LOAD R9,R2,I-ARSIZE SUB R10,R9,R3 ; test = i - j; BEQ ENDCHECK ; if (test != 0) { ; -- parameter j already there LIS R4,10 ; -- parameter field width LIL R1,PUTDEC JSRS R1,R1 ; putdec( j, 10 ) LEA R3,FOUND LIL R1,PUTSTR JSRS R1,R1 ; putstr( " returned when " ) LOAD R3,R2,I-ARSIZE ; -- parameter i LIS R4,10 ; -- parameter field width LIL R1,PUTDEC JSRS R1,R1 ; putdec( i, 10 ) LEA R3,EXPECT LIL R1,PUTSTR JSRS R1,R1 ; putstr( " expected." ) ENDCHECK: ; } CMPI R8,-8 ; -- r9 holds test here BEQ ENDGUARD ; if (guardsum != -8) { LEA R3,GUARD LIL R1,PUTSTR JSRS R1,R1 ; putstr( " R8-15 violated." ) LIS R10,1 ; test = 1 ENDGUARD: ; } TESTR R10 ; -- r9 holds test, if nonzero, message needs LF BZS NOLINE ; if (test != 0) { LIS R3,LF LIL R1,PUTCHAR JSRS R1,R1 ; putch( '\n' ) NOLINE: ; } ADDI R2,R2,-ARSIZE LOAD R15,R2,R15SV LOAD R14,R2,R14SV LOAD R13,R2,R13SV LOAD R12,R2,R12SV LOAD R11,R2,R11SV LOAD R10,R2,R10SV LOAD R9,R2,R9SV LOAD R8,R2,R8SV LOADS PC,R2 FOUND: ASCII " returned when ",0 EXPECT: ASCII " expected.",0 GUARD: ASCII " R8-15 violated.",0 END