0707070000020074761006440000000000000000010541400002606355300000500000000003Size75 0707070000020075101006440000000000000000010525630002606331000000600000000123Files./Size ./Files ./Install ./Makefile ./Name ./Remove ./help ./prime_num.s ./prm7meg 0707070000020071711006440000000000000000010677550002606347700001000000000702Install echo " prm7meg --> ${HOME}/Filecabinet/PRIME/SRC prime_num.s --> ${HOME}/Filecabinet/PRIME/SRC Makefile --> ${HOME}/Filecabinet/PRIME/SRC help --> ${HOME}Filecabinet/PRIME/SRC " mkdir ${HOME}/Filecabinet/PRIME mkdir ${HOME}/Filecabinet/PRIME/SRC mv prm7meg ${HOME}/Filecabinet/PRIME/SRC mv prime_num.s ${HOME}/Filecabinet/PRIME/SRC mv Makefile ${HOME}/Filecabinet/PRIME/SRC mv help ${HOME}/Filecabinet/PRIME/SRC 0707070000020071421006440000000000000000010676710402320066200001100000000226Makefile# Makefile prm7meg: prime_num.o ld -o prm7meg /lib/crt0s.o /lib/shlib.ifile prime_num.o strip prm7meg rm prime_num.o prime_num.o: prime_num.s 0707070000020071651006440000000000000000010525470002606321300000500000000062NamePRIME - Prime number generator V1.0 via THE STORE 0707070000020072361006440000000000000000010677560402320175100000700000000327Remove rm /usr/bin/prm7meg rm ${HOME}/Filecabinet/PRIME/SRC/* rm ${HOME}/Filecabinet/PRIME/DOC/* rmdir ${HOME}/Filecabinet/PRIME/SRC rmdir ${HOME}/Filecabinet/PRIME/DOC rmdir ${HOME}/Filecabinet/PRIME 0707070000020072021006440000000000000000010662770402320036000000500000011434helpprime.help The prime_num.s program is a DEMONSTRATION PROGRAM that shows the great power of the 68010 CPU of the Unix PC and its RAM access. It is written in assembler and addresses most of its variables through registers. It mainly has value in demonstrating the power of the machine to math officianados, since many computer users out there don't even know exactly what a prime number is, or at the very least, they don't care to know. Prime_num.s is started by just typing in its executable program name, which, according to the enclosed make file, would be: "prm7meg". It then lays out a very large, bitmapped area in core (RAM), initializes this area to a certain bit pattern, and then proceeds to throw 1-bits out to this area so that all bits corresponding to non-prime numbers are made equal to 1. The bit pattern is organized so that the first bit stands for the number, 3, the next for 5, and so on. All bits that have a value of zero at the end of the 1-bit throws, correspond to prime numbers. When the program is finished, it retains, in core, a bitmap pattern which has EVERY prime number from 1 to over 7,000,000 designated within it. The second part of prm7meg prompts the user for what part of this area he wishes to interrogate, and for how long, so as to dump out all consecutive primes, twin primes, triple primes, or double twin primes, within its boundaries. A sample output follows: Value of address register A7 on entry was = 2ff864 Value of sbrk was = 1030486 This is the prime_num program. It calculates *all* the primes from 3 to 7033100, and saves the results as a bitmap in core. Program will start NOW! Finis! All the primes have been calculated and are now in a bitmap in core. Enter the starting number to look for primes: (just return carriage to finish) 1201 Enter the number of primes to be dumped: (just return carriage to finish) 15 Indicate: "d", "t", or "q" for twin, triple or quadruple primes, or not: 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 Enter the starting number to look for primes: (just return carriage to finish) 50001 Enter the number of primes to be dumped: (just return carriage to finish) 3 Indicate: "d", "t", or "q" for twin, triple or quadruple primes, or not: d 50021 50023 50051 50053 50129 50131 Enter the starting number to look for primes: (just return carriage to finish) 876123 Enter the number of primes to be dumped: (just return carriage to finish) 3 Indicate: "d", "t", or "q" for twin, triple or quadruple primes, or not: t 877397 877399 877403 877867 877871 877873 878831 878833 878837 Enter the starting number to look for primes: (just return carriage to finish) 6789001 Enter the number of primes to be dumped: (just return carriage to finish) 13 Indicate: "d", "t", or "q" for twin, triple or quadruple primes, or not: q 6796631 6796633 6796637 6796639 6843371 6843373 6843377 6843379 6880871 6880873 6880877 6880879 6884741 6884743 6884747 6884749 6900911 6900913 6900917 6900919 6915191 6915193 6915197 6915199 6918011 6918013 6918017 6918019 6918341 6918343 6918347 6918349 6925151 6925153 6925157 6925159 6937961 6937963 6937967 6937969 6942491 6942493 6942497 6942499 6945551 6945553 6945557 6945559 6949331 6949333 6949337 6949339 Enter the starting number to look for primes: (just return carriage to finish) Finis All! Value of address register A7 on exit was = 2ff864 The setbuf() call in the program below allows this program to be readily run in a "tee" pipe, like so: prm7meg|tee prm7out. Running the program like this allows the saving of the output in file prm7out. The running of the above program, in a 1 REAL Meg machine, takes less than 1 minute! For users with higher REAL megs: 1 Meg -- set MAXNUM=7033100 and MAXFACT=2651 1 1/2 Megs -- set MAXNUM=15023000 and MAXFACT=3875 2 Megs -- set MAXNUM=23040000 and MAXFACT=4799 2 1/2 Megs -- set MAXNUM=31040000 and MAXFACT=5571 The three last settings will run in twice, three, and four times as much time as prm7meg, but will calculate all the primes to higher numbers, as indicated. If you run any of these programs in too little core, they will work, but VERY slowly, because enormous swapping will have to be done by the machine to keep all that RAM available to it "simultaneously". So, beware! Install and Remove files for these programs can easily be created by the user. The best directory to save them would probably be /usr/games. PLEASE direct comments and questions to: David Solan Objective Programming Incorporated Post Office Box 123 Norwalk, CT 06856-0123 (203) 866-6900 (voice only) This program is hereby given up by me to the public domain -- I created it entirely by myself. ................David Solan 0707070000020072121006440000000000000000010677210002606226000001400000043664prime_num.s# prime_num.s file "prime_num.s" global main # This program will lay out a bit-mapped area (Bitall) in storage, # which is bitmapped for all odd numbers starting from 3 on up, and the # program will then throw out 1 bit to all those bits representing # numbers that are not prime. It will do this by going through all # factors of maxnum from 3 to its square root, incrementing by +2 (or # more) at a time, and then pass these factors to throw_bits, which will # actually do the "bit-out"'s by taking multiples of each factor of 7, # 11, 13, 17, 19, ...etc. times it to actually do the bit-out. set NUMSVREGS,13 #save 13 input/your-own registers set MVOFFSET,-(4*NUMSVREGS) #offset for move of 13 registers set MAXNUM,7033100 #the maximum number looked at now set MAXFACT,2651 #square root of above - max factor looked at # Bitall is bitmapped so: 1st byte = numbers 3 to 17, odd only, # 2nd byte = numbers 19 to 33, odd only, and so on lcomm Bitall,(MAXNUM/16+450) #reserve enough bytes for bit-out area data 0 START: byte 'T,'h,'i,'s,' ,'i,'s,' ,'t,'h,'e,' ,'p,'r,'i,'m,'e,'_ byte 'n,'u,'m,' ,'p,'r,'o,'g,'r,'a,'m,'.,'\n byte 'I,'t,' ,'c,'a,'l,'c,'u,'l,'a,'t,'e,'s,' ,'*,'a,'l,'l byte '*,' ,'t,'h,'e,' ,'p,'r,'i,'m,'e,'s,' ,'f,'r,'o,'m,' ,'3 byte ' ,'t,'o,' ,'%,'d,',,'\n,'a,'n,'d,' ,'s,'a,'v,'e,'s byte ' ,'t,'h,'e,' ,'r,'e,'s,'u,'l,'t,'s,' ,'a,'s,' ,'a byte ' ,'b,'i,'t,'m,'a,'p,' ,'i,'n,' ,'c,'o,'r,'e,'.,'\n,'P,'r,'o,'g,'r,'a,'m byte ' ,'w,'i,'l,'l,' ,'s,'t,'a,'r,'t,' ,'N,'O,'W,'!,0x07,'\n,'\n,0x00 SBREAK: byte 'V,'a,'l,'u,'e,' ,'o,'f,' ,'s,'b,'r,'k,' ,'w,'a,'s,' ,'=,' ,'%,'d,'\n,0x00 A7OUT: byte 'V,'a,'l,'u,'e,' ,'o,'f,' ,'a,'d,'d,'r,'e,'s,'s,' ,'r,'e,'g byte 'i,'s,'t,'e,'r,' ,'A,'7,' ,'o,'n,' ,'e,'n,'t,'r,'y,' ,'w,'a,'s,' ,'=,' ,'%,'x,'\n,0x00 A7IN: byte 'V,'a,'l,'u,'e,' ,'o,'f,' ,'a,'d,'d,'r,'e,'s,'s,' ,'r,'e,'g byte 'i,'s,'t,'e,'r,' ,'A,'7,' ,'o,'n,' ,'e,'x,'i,'t,' ,'w,'a,'s,' ,'=,' ,'%,'x,'\n,0x00 skip_factor: byte 'X #flag to tell you to skip +2 on a factor even maxnum: long (MAXNUM) #the maximum number looked at now maxfactor: short (MAXFACT) #square root of above - max factor looked at text 0 main: link %fp,&(-4+2*MVOFFSET) #additional -4 allows bsr or jsr branch to other routines! movm.l &0x1FFF,MVOFFSET(%fp) #save 13 registers of caller mov.l %sp,%a5 #save reg a7 mov.l &0,(%sp) #indicate no buffering at all mov.l &_iob+14,-(%sp) #second occurrence of _iob = stdout jsr setbuf #remove all buffering on output # (above line = setbuf(stdout, (char*)0); mov.l %a5,(%sp) mov.l &A7OUT,-(%sp) #pass (last) address of the printf format # A jsr to printf has, as the argument on the bottom of the passed # stack list (but before the return address), the format of the output. # All the arguments that this format needs are then put on the stack # above it. They are on the stack in the order in which they would # appear in a C call to printf, but to accomplish this, are put on the # stack, by predecrement addressing, in reverse order. jsr printf clr.l (%sp) #pass 0 to sbrk jsr sbrk mov.l %d0,(%sp) mov.l &SBREAK,-(%sp) jsr printf add.l &12,%sp # here we pre-initialize Bitall to indicate non-prime for every 3 and every 5 numbers: mov.l &0x1259A4B3,Bitall #initializes 1st 4 bytes mov.l &0x496692CD,Bitall+4 #initializes 2nd 4 bytes mov.l &0x259A4B34,Bitall+8 #etc. mov.l &0x96692CD2,Bitall+12 lea Bitall+1,%a0 #2nd byte lea Bitall+16,%a1 #17th byte mov.w &(MAXFACT/4),%d0 #number of loops minus 1 mov.w &(MAXFACT/4),%d1 #number of loops multiplier minus 1 initbita: mov.b (%a0)+,(%a1)+ #move +15 bytes ahead here dbra %d0,initbita #loop to initialize Bitall more mov.w &(MAXFACT/4),%d0 #number of loops dbra %d1,initbita #loop to initialize Bitall more mov.l &MAXNUM,(%sp) #move value to be printed mov.l &START,-(%sp) #move address of starting byte to print jsr printf add.l &4,%sp #adjust stack pointer to original address # INITIALIZES: clr.l %d1; clr.l %d4 #clear registers # %d1 (byte) = the 3-count, removing all factors divisible by 3 mov.b &2,%d1 #first count in 3-count mov.l &0x1FFFFFFF,%d2 #29 lo-order bits are on mov.l &0x00000080,%d3 #a hi_order 1-bit in the byte mov.l &0xE0000000,%a3 #3 hi-order bits are on # %a4 (word) = the factor to be added over and over to "bit out" # all non-prime numbers generated by throw_bits: mov.l &7,%a4 #first factor to be tested # the following is good for the rest of the pgm: lea Bitall,%a1 #register %a1 has addr(Bitall) for rest of pgm gnext_fact: mov.b &'A,skip_factor #set flag to not skip +2 sub.b &1,%d1 #subtract 1 from 3-count bgt.b keepon1 mov.b &'X,skip_factor #set flag to skip +2 mov.b &3,%d1 #count in 3-count keepon1: cmp.b skip_factor,&'X #is signal set to add +2 more? bne.b test_more add.w &2,%a4 #get next factor to be used bra.b gnext_fact #try again test_more: # following tests if the factor passed was indeed prime (if not, tries again): mov.l %a4,%d5 #%d5 has bit-number X 2 now asr.l &1,%d5 #divide number by 2 - now have global bit-number sub.l &1,%d5 #subtract 1, so that global bit-number starts at 0 ror.l &3,%d5 #divide %d5 by 8, remainder in hi-order mov.l %a3,%d7 #move 3 hi-order bits in and.l %d5,%d7 #move 3 hi-order (remainder) bits to %d7 rol.l &3,%d7 #shift remainder to lo-order of %d7 mov.b %d3,%d6 #temporarily put a 1-bit in lo-order byte of %d6 lsr.b %d7,%d6 #shift for remainder number of bits and.l %d2,%d5 #remove 3 hi-order bits from %d5 and.b 0(%a1,%d5.l),%d6 #actually do the test to see if prime! tst.b %d6 #was there a 1 bit there? beq.b throw_bits #Found a Prime if a 0 bit there - branch add.w &2,%a4 #get next factor to be used bra.b gnext_fact #try again throw_bits: # Jump to here means got a prime factor to "bit out". # %d0 (long) = actual number (to be tested for prime) used # to "bit out" Bitall by throw_bits: mov.l %a4,%d0 #first factor put in all of %d0 asl.w &1,%d0 #multiply factor by 2 mov.l %d0,%a2 #save (2 X factor) in %a2 asl.l &2,%d0 #multiply factor by 8 sub.l %a4,%d0 #factor now multiplied by 7 in %d0 mov.w &0,%d4 #put initial every-3-times exclusion number in bit_out_again: mov.l %d0,%d5 #put non-prime num in %d5 as a bit-number asr.l &1,%d5 #divide by 2 - now have global bit-number to "bit-out" sub.l &1,%d5 #subtract 1, so that bit-number starts at 0 ror.l &3,%d5 #divide %d5 by 8, remainder in hi-order mov.l %a3,%d7 #move 3 hi-order bits in and.l %d5,%d7 #move 3 hi-order (remainder) bits to %d7 rol.l &3,%d7 #shift remainder to lo-order of %d7 mov.b %d3,%d6 #temporarily put a 1-bit in lo-order byte of %d6 lsr.b %d7,%d6 #shift for remainder number of bits and.l %d2,%d5 #remove 3 hi-order bits from %d5 # or.b %d6,0(%a1,%d5.l) #actually do the bit-out to indicate non-prime! # add_twice_fact: add.l %a2,%d0 #add (2 X factor) to %d0 dbra %d4,bit_out_again #bit-out another non-prime mov.w &2,%d4 #put back 3-counter cmp.l %d0,maxnum #has %d0 reached maximum number? blt.b add_twice_fact # if fall thru, look for next factor add.w &2,%a4 #get next factor to use by bumping by +2 cmp.w %a4,maxfactor #compare to maximum factor to be used ble.w gnext_fact #go back for another factor # fall thru here means we have finished! # Go thru some bit numbers here and print out all 0 bits: data 0 set DBLANK,0x64202020 #set to "d " set QBLANK,0x71202020 #set to "q " set TBLANK,0x74202020 #set to "t " FINIS: byte 'F,'i,'n,'i,'s,'!,0x07,0x00 even begoutnum: long 8 #first number to look at numsout: short 8 #number of prime numbers to print t_ind: byte 'd #indicates whether double or triple primes-only desired finisa: byte '\n,'F,'i,'n,'i,'s,' ,'A,'l,'l,'!,'\n,0x07,0x00 inform1: byte '\n,'A,'l,'l,' ,'t,'h,'e,' ,'p,'r,'i,'m,'e,'s,' ,'h,'a,'v,'e byte ' ,'b,'e,'e,'n,' ,'c,'a,'l,'c,'u,'l,'a,'t,'e,'d byte ' ,'a,'n,'d,' ,'a,'r,'e,' ,'n,'o,'w,' ,'i,'n,' ,'a,' ,'b,'i,'t byte 'm,'a,'p,' ,'i,'n,' ,'c,'o,'r,'e,'.,0x00 prompt1: byte '\n,'E,'n,'t,'e,'r,' ,'t,'h,'e,' ,'s,'t,'a,'r,'t,'i,'n,'g,' ,'n,'u,'m,'b,'e,'r byte ' ,'t,'o,' ,'l,'o,'o,'k,' ,'f,'o,'r,' ,'p,'r,'i,'m,'e,'s,':,'\n,'\t,0x00 promptp: byte '(,'j,'u,'s,'t,' ,'r,'e,'t,'u,'r,'n,' ,'c,'a,'r byte 'r,'i,'a,'g,'e,' ,'t,'o,' ,'f,'i,'n,'i,'s,'h,'),'\t,0x00 prompt2: byte '\n,'E,'n,'t,'e,'r,' ,'t,'h,'e,' ,'n,'u,'m,'b,'e,'r,' ,'o,'f byte ' ,'p,'r,'i,'m,'e,'s,' ,'t,'o,' ,'b,'e,' ,'d,'u,'m,'p,'e,'d,':,'\n,0x00 prompt3: byte '\n,'I,'n,'d,'i,'c,'a,'t,'e,':,' ,'",'d,'",',,' ,'",'t,'",',,' ,'o,'r,' ,'",'q,'",' ,'f byte 'o,'r,' ,'t,'w,'i,'n,',,' ,'t,'r,'i,'p,'l,'e,' ,'o,'r,' ,'q,'u,'a,'d,'r,'u,'p byte 'l,'e,' ,'p,'r,'i,'m,'e,'s,',,' ,'o,'r,' ,'n,'o,'t,':,' ,0x00 even #MUST be an even boundary! set LENCLR,55 #set length of Input_area Input_area: space (LENCLR) #reserve bytes for input from crt CR0: byte '\n,0x00 output: byte '%,'d,' ,' ,0x00 text 0 mov.l &FINIS,(%sp) jsr printf mov.l &inform1,(%sp) jsr printf start_out: mov.l &CR0,(%sp) jsr printf bsr.w Clear_rtn #clear Input_area mov.l &prompt1,(%sp) jsr printf mov.l &promptp,(%sp) jsr printf bsr.w Input_crt #feed in a line to Input_area # upon return, %d7 has the number of bytes entered! cmp.b %d7,&0 #is number of bytes = 0? ble.w finout #if 0 or > 127 entered, final end of pgm lea Input_area,%a1 #load addr(Input_area) add.l %d7,%a1 #(%a1) is now 1 byte past last digit entered clr.l %d0 #zero final result mov.l &1,%d1 #put 1 in %d1 = 0th power of 10 clr.l %d6 #save of the counter if > 5 digits cmp.b %d7,&5 #is it 5 digits? dbgt %d7,analoop #if not > 5 digits, subtract 1 and branch mov.b %d7,%d6 #save full count of digits sub.b &5,%d6 #subtract so that counter of spcloop is correct mov.b &4,%d7 #put in 5-count for this loop analoop: clr.w %d2 #zero intermediate byte area mov.b -(%a1),%d2 #move lo-order digit in cmp.b %d2,&'0 #compare to character "0" blt.b start_out #if < 0, no good cmp.b %d2,&'9 #compare to character "9" bgt.b start_out #if > 9, no good sub.b &'0,%d2 #convert to decimal number mulu %d1,%d2 #multiply by a power of 10 add.l %d2,%d0 #add result mulu &10,%d1 #increase %d1 by power of 10 dbra %d7,analoop #keep on trucking dbra %d6,spcloop #if branch, > 5 digits entered begoutfn: lsr.l &1,%d0 #divide by 2 lsl.l &1,%d0 #restore it, but always even sub.l &1,%d0 #insure odd number and -2 from start! cmp.l %d0,maxnum #is inputted num > max number? bgt.w start_out #if greater than, try again # begoutnum (long) is the starting number to look at: mov.l %d0,begoutnum add.l &2,%d0 #move in first value looked at mov.l %d0,(%sp) #move in value to be printed mov.l &output,-(%sp) #move in addr of string to output jsr printf add.l &4,%sp #adjust stack pointer to return address bsr.w Clear_rtn #clear Input_area mov.l &prompt2,(%sp) jsr printf mov.l &promptp,(%sp) jsr printf bsr.w Input_crt #feed in a line to Input_area cmp.b %d7,&0 #is number of bytes = 0? ble.w start_out #if 0 or > 127 entered, go back to prompt1 lea Input_area,%a1 #load addr(Input_area) add.l %d7,%a1 #(%a1) is now 1 byte past last digit entered clr.l %d0 #zero final result mov.l &1,%d1 #put 1 in %d1 = 0th power of 10 dbra %d7,analoop2 #subtract 1 at first analoop2: clr.w %d2 #zero intermediate byte area mov.b -(%a1),%d2 #move lo-order digit in cmp.b %d2,&'0 #compare to character "0" blt.w start_out #if < 0, no good cmp.b %d2,&'9 #compare to character "9" bgt.w start_out #if > 9, no good sub.b &'0,%d2 #convert to decimal number mulu %d1,%d2 #multiply by a power of 10 add.l %d2,%d0 #add result mulu &10,%d1 #increase %d1 by power of 10 dbra %d7,analoop2 #keep on trucking # numsout (word) is the count of the number of primes to look at: mov.l %d0,(%sp) #move in value to be printed sub.w &1,%d0 #insure 1 less for proper count mov.w %d0,numsout mov.l &output,-(%sp) #move in addr of string to output jsr printf add.l &4,%sp #adjust stack pointer to return address bsr.w Clear_rtn #clear Input_area mov.l &prompt3,(%sp) jsr printf bsr.w Input_crt #feed in a line to Input_area mov.l &Input_area,(%sp) #move in addr of char value to be printed mov.b &0x00,Input_area+4 #move in ending character jsr printf mov.b &'X,t_ind #set t_ind off cmp.l Input_area,&DBLANK #was just a "d" entered? beq.b twin_er cmp.l Input_area,&TBLANK #was just a "t" entered? beq.b twin_er cmp.l Input_area,&QBLANK #was just a "q" entered? bne.b not_triple twin_er: mov.b Input_area,t_ind #set t_ind on to correct value not_triple: mov.l &CR0,(%sp) jsr printf # restore %a1 to the address of Bitall: lea Bitall,%a1 #register %a1 again has addr(Bitall) # %d0 (long) is the starting number to look at: mov.l begoutnum,%d0 # %d1 (word) is the count of the number of primes to look at: mov.w numsout,%d1 mov.l &0,%a4 mov.l &0,%d2 bra.w printit2 spcloop: mov.l &1,%d1 #put 1 in %d1 = 0th power of 10 clr.l %d3 #zero intermediate result analoop3: clr.w %d2 #zero intermediate byte area mov.b -(%a1),%d2 #move lo-order digit in cmp.b %d2,&'0 #compare to character "0" blt.w start_out #if < 0, no good cmp.b %d2,&'9 #compare to character "9" bgt.w start_out #if > 9, no good sub.b &'0,%d2 #convert to decimal number mulu %d1,%d2 #multiply by a power of 10 add.l %d2,%d3 #add result mulu &10,%d1 #increase %d1 by power of 10 dbra %d6,analoop3 #keep on trucking mulu &3125,%d3 #first multiply this result by 3125 asl.l &5,%d3 #now, multiply altogether by 100,000 add.l %d3,%d0 #add to final result bra.w begoutfn #branch back to finish up prntquad: cmp.l %a2,&0 #was first prime of quadruple found before? beq.w printit3 #branch if no prime mov.b &1,%d4 #add +1 to counter of primes bra.b prnttrp1 prnquad: cmp.l %d2,&0 #is the 2nd prime a twin found just before? beq.w printit3 #continue on if not mov.l %a2,%a0 #move in value to be printed bsr.w Prnanum #print mov.l %a3,%a0 #move in value to be printed bsr.w Prnanum #print bra.b spprntp1 prnttrp: mov.b &0,%d4 #clear counter prnttrp1: cmp.l %a4,&0 #was prime found before? beq.b prnttrp2 #branch if no prime mov.l %a4,%a0 #move in value to be printed add.b &1,%d4 #add +1 to counter of primes prnttrp2: cmp.l %a3,&0 #was prime found before? beq.b prnttrp3 mov.l %a3,%a0 #move in value to be printed add.b &1,%d4 prnttrp3: cmp.b %d4,&0 #no primes at all? beq.b printit3 #continue on if nothing cmp.b %d4,&2 #two primes? beq.b twprntp2 # fall thru means there must be 1 prime so far cmp.b t_ind,&'q #were only quadruple primes requested? beq.b printit3 #continue on if only 1 prime cmp.l %d2,&0 #is the 2nd prime a twin found just before? beq.b printit3 #continue on if not bsr.w Prnanum #print last prime and go on bra.b spprntp1 twprntp2: # means there must be 2 primes cmp.b t_ind,&'q #were only quadruple primes requested? beq.b prnquad # %a3 has already been moved to %a0 bsr.w Prnanum #print it mov.l %a4,%a0 #move in value to be printed bsr.w Prnanum #print it # we could insure against double printing of double twins here if we wished bra.b spprntp2 printitt: cmp.b t_ind,&'t #were only triple primes requested? beq.b prnttrp #branch if triple only cmp.b t_ind,&'q #were only quadruple primes requested? beq.w prntquad #branch if quadruple only cmp.l %d2,&0 #was twin prime found just before? beq.b printit3 #continue on if not spprntp1: mov.l %d2,%a0 #move in value to be printed bsr.w Prnanum #print it spprntp2: mov.l %d0,%a0 #move in value to be printed bsr.w Prnanum #print it dbra %d1,printit3 #count out number of groups of primes bra.w start_out #go back to fgetc prompts printit2: mov.l %a3,%a2 #move prime number back in list mov.l %a4,%a3 #again mov.l %d2,%a4 #again mov.l &0,%d2 #indicate last number was *not* prime bra.b printit4 printit3: mov.l %a3,%a2 #move prime number back in list mov.l %a4,%a3 #again mov.l %d2,%a4 #again mov.l %d0,%d2 #indicate last number *was* prime printit4: add.l &2,%d0 #go to next number mov.l %d0,%d5 #%d5 has bit-number X 2 now asr.l &1,%d5 #divide number by 2 - now have global bit-number sub.l &1,%d5 #subtract 1, so that bit-number starts at 0 ror.l &3,%d5 #divide %d5 by 8, remainder in hi-order data 0 even lo_order29: long 0x1FFFFFFF #29 lo-order bits are on hi_order3: long 0xE0000000 #3 hi-order bits are on one_bitr: byte 0x80 #a hi-order 1-bit text 0 mov.l hi_order3,%d7 #move 3 hi-order bits in and.l %d5,%d7 #move 3 hi-order (remainder) bits to %d7 rol.l &3,%d7 #shift remainder to lo-order of %d7 mov.b one_bitr,%d6 #temporarily put a 1-bit in lo-order %d6 lsr.b %d7,%d6 #shift for remainder number of bits and.l lo_order29,%d5 #remove 3 hi-order bits from %d5 and.b 0(%a1,%d5.l),%d6 #actually do the test to see if prime! tst.b %d6 #was there a 1 bit there? bne.b printit2 #Not prime if a 1 bit there - branch # else, FOUND A PRIME here - value is in %d0! cmp.b t_ind,&'X #are all primes requested to be printed? bne.b printitt #if not, must check above mov.l %d0,%a0 #move in value to be printed bsr.b Prnanum #print it dbra %d1,printit4 #print another, if prime bra.w start_out #go back to fgetc prompts finout: mov.l &finisa,(%sp) jsr printf mov.l %sp,(%sp) mov.l &A7IN,-(%sp) jsr printf add.l &4,%sp movm.l MVOFFSET(%fp),&0x1FFF #restore 13 registers of caller unlk %fp rts #FINAL RETURN! Prnanum: movm.l &0x1FFF,2*MVOFFSET(%fp) #save your own 13 registers mov.l %a0,-(%sp) #move in value to be printed mov.l &output,-(%sp) #move in addr of string to output jsr printf add.l &8,%sp #adjust stack pointer to return address movm.l 2*MVOFFSET(%fp),&0x1FFF #restore your own 13 registers rts Clear_rtn: mov.b &' ,Input_area #space out first byte lea Input_area,%a2 #load addr lea Input_area+1,%a3 #load addr+1 mov.w &LENCLR-2,%d3 #number of bytes moved - 1 clr_loop: mov.b (%a2)+,(%a3)+ #move 1 byte ahead dbra %d3,clr_loop #loop to blank out more rts Input_crt: clr.l %d7 #zero index pointer to Input_area crt1in: mov.l &_iob,-(%sp) #set up for fgetc (from stdin) # fgetc gets next byte from crt and puts in %d0, puts number in %d1: jsr fgetc add.l &4,%sp #adjust stack pointer to return address cmp.b %d0,&10 #is byte just read in a Carriage Return? beq.b crtCR #Yes. lea Input_area,%a1 #load addr(Input_area) mov.b %d0,0(%a1,%d7.w) #move byte just read in to Input_area add.b &1,%d7 #add +1 for next byte from crt bra.b crt1in crtCR: rts 0707070000020075071007550000000000000000010525460002606230000001000000007204prm7megRXd¿ „¶Ò .text .data „ @.bss „ „¶Ò€.lib¹V¹V/<¹VN¹1X OQ.˜/HJ˜fÿü/H#È0N¹