; JetPrime.Z80 ; ; Z80 Seive Benchmark. ; Bridger Mitchell, Plu*Perfect Systems 1/13/87 ; Translated for assembly with ZAS or Z80ASM ; by Bruce Morgen, North American One-Eighty Group ; 10:24:28 January 22, 1987. ; ; Count the number of primes in [0...SIZE]. ; Z80 hand-coded ASM version of BYTE benchmark. ; ; Remark. I put this together after receiving the Borland ; Turbo Modula-2 PRIME.MOD file, to get some indication of ; the relative gain from hand-coding over a using compiler with ; an early reputation for fast code. ; ; I believe it's a fair test, as the high-level language ; implementations of the benchmark also use compiled constants. ; However, my routine doesn't call a formatted decimal output routine, ; and it would be best to remove that from all comparative tests, ; anyway -- compilers vary a great deal in the overhead required ; to format. ; ; Doubtless someone has done this before ... it was faster to ; write a few lines than dig into back magazine and newsletter issues. ; ; This source file was assembled with the Echelon ZAS assembler. ; Syntax: ZAS JETPRIME H (followed by) ; MLOAD JETPRIME ; Allocate flags[] so that flags[SIZE+1] begins on a new page. ; Use high-byte compare to terminate loops. ; SIZE EQU 8190 ; Largest integer to be checked ANSWER EQU 1899 ; Number of primes in [0...SIZE] ; TOP EQU FREE + [SIZE + [100H - [00FFH AND SIZE]]] ; PAGEND EQU [HIGH TOP] AND 00FFH ; Page following flag[SIZE] ; FLAGS EQU TOP - [SIZE +1] ; There are 0...SIZE = SIZE+1 ; BDOS EQU 5 CR EQU 0DH LF EQU 0AH ; NITER EQU 10 ; Number of iterations, for timing. ; ORG 100H ; ; use CCP stack ; TEST: LD DE,SIGNON ; Banner & prompt LD C,9 CALL BDOS CALL WAITCR ; Wait for CR ; LD A,NITER ; Set # iterations' MORE: PUSH AF ; CALL PRIMES POP AF DEC A JP NZ,MORE ; LD HL,ANSWER ; Verify answer SBC HL,BC ; (cy clear) LD DE,DONMSG JR Z,SAYEND ; Z - it's correct LD DE,BADMSG SAYEND: LD C,9 CALL BDOS ; EXIT: LD DE,RETMSG ; Ask for CR again LD C,9 ; And exit to CCP CALL BDOS ; WAITCR: LD C,6 ; Wait LD E,0FFH CALL BDOS CP CR JR NZ,WAITCR LD E,A ; Echo a CR LD C,2 JP BDOS ; SIGNON: DB CR,LF DB 'JetPrime Z80 -- BYTE Seive Benchmark - 10 iterations' RETMSG: DB CR,LF DB 'Hit .$' ; DONMSG: DB CR,LF DB '1899 Primes$' ; BADMSG: DB CR,LF DB 'Wrong!$' ; ; PRIMES: LD HL,FLAGS ; Set all flags TRUE LD DE,FLAGS+1 LD BC,SIZE LD (HL),01H LDIR ; ; initialize registers ; Bc = count = 0 already LD D,B ; De = i = 0 LD E,B LD HL,FLAGS ; &flags[0] EXX ; Bc' = &flags[0] LD BC,FLAGS EXX LD A,PAGEND-1 ; Last page of flags[] ; LP1: BIT 0,(HL) ; If flag[i] == TRUE JP Z,NEXT ; PUSH DE ; Set up for inner loop EXX ; & count this prime POP HL ; Hl' = i LD D,H ; De' = i LD E,L ADD HL,HL ; *2 INC HL INC HL INC HL ; +3 EX DE,HL ; De' = prime = i + i + 3, hl' = i ADD HL,DE ; Hl' = k = prime + i ADD HL,BC ; Hl' = &flag[k] ; LP2: CP H ; While k <= SIZE JR C,LP2X RES 0,(HL) ; Flag[k] = FALSE ADD HL,DE ; Hl' = k = hl' + prime JP LP2 ; LP2X: EXX ; Count the prime INC BC ; Count++ ; ; do next i ; NEXT: INC HL ; &keys[]++ INC DE ; I++ CP H JP NC,LP1 RET ; Bc = count of primes ; DS [100H - [$ AND 00FFH]] FREE: DS 0 END