Subject: Re: Please convert this SLOW BASIC program to machine language Message-ID: <37FDDBAC.37D54FBF@swbell.net> From: Rubywand Reply-To: rubywand@swbell.net X-Mailer: Mozilla 4.51 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.sys.apple2.programmer References: <37D258CF.F8264C02@swbell.net> <7slde5$nkc$1@nnrp1.deja.com> <7t4vtc$mgi$1@nnrp1.deja.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 79 Date: Fri, 08 Oct 1999 06:55:24 -0500 NNTP-Posting-Host: 207.193.8.17 X-Complaints-To: abuse@swbell.net NNTP-Posting-Date: Fri, 08 Oct 1999 04:54:45 PDT Organization: SBC Internet Services bruzzi@hotmail.com writes ... > > Hello, could anybody please convert this short BASIC program into > machine language, that I can feed into the built-in machine langauge > monitor on the Apple IIe? Please post your code here...thanks. > > 10 REM PEP Calculator - (C) 1993-99 Alan C. Bruzzi > 20 DIM SA%(163) > 30 DIM MU%(163) > 40 DIM MX%(163, 99) > 1000 REM Main routine to enter the factorial number, > 1010 REM call the factorial function, and print out the answer. > 1020 PRINT "PEP Calculator" > 1030 PRINT : INPUT "Enter number (0-100): ", N > 1040 IF N >= 0 AND N <= 100 THEN 1070 > 1050 PRINT "Number is greater than 100 or less than 0." > 1060 END: REM exits the program > 1070 PRINT "Computing " + STR$(N) + "!" > 1080 IF N > 1 THEN 1110 > 1090 PRINT "The answer is: 1" > 1100 END > 1110 LET F = INT((N * LOG(N) - N) / LOG(10) + 2) + 1: REM Calculus 2 > equation > 1120 LET MU%(162) = 1 > 1130 GOSUB 2000: REM Calculate the Factorial of N > 1140 PRINT "The answer is: " > 1150 REM The following routine leaves out excess zeros before the first > 1160 REM non-zero digit. > 1170 FOR N = 157 TO 0 STEP -1 > 1180 IF SA%(N) <= 0 THEN 1230 > 1190 LET CH = 1 > 1200 LET D = D + 1 > 1210 PRINT STR$(SA%(N)); > 1220 GOTO 1260 > 1230 IF SA%(N) <> 0 OR CH <> 1 THEN 1260 > 1240 PRINT "0"; > 1250 LET D = D + 1 > 1260 NEXT N > 1270 PRINT > 1280 PRINT "Number of digits = "; STR$(D) > 1290 PRINT > 1300 END > 1998 REM > 1999 REM This subroutine calculates the Factorial of N and returns it > in SA%() > 2000 FOR J = N TO 1 STEP -1 > 2020 LET BW = 162 > 2030 LET FW = 0 > 2040 REM 1) The following routine multiplies digits > 2041 REM Each column is a single digit > 2050 FOR C = 162 TO 162 - F STEP -1 > 2060 LET MX%(C, 1) = MU%(C) * J > 2070 NEXT C > 2080 REM 2) The following routine adds up the columns and rows. > 2090 FOR C = 162 TO 162 - F STEP -1 > 2100 LET A = 0 > 2110 LET R = 1 > 2120 FOR K = 1 TO 98 > 2130 LET A = A + MX%(C, R) > 2140 LET R = R + 1 > 2150 IF A <= 9 THEN 2200 > 2160 LET MX%(C, 1) = MX%(C, 1) - 10 > 2170 LET MX%(C - 1, 1) = MX%(C - 1, 1) + 1 > 2180 LET A = MX%(C, 1) > 2200 NEXT K > 2210 LET MU%(BW) = A > 2220 LET BW = BW - 1 > 2230 LET SA%(FW) = A > 2240 LET FW = FW + 1 > 2250 NEXT C > 2270 NEXT J > 2280 RETURN .... You could get a kind of machine language version which would execute a good deal faster by running your program through one of the BASIC compilers such as TASC or Einstein. Rubywand