; JetPrime.ASM ; ; Z80 Seive Benchmark. ; Bridger Mitchell, Plu*Perfect Systems 1/13/87 ; ; 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 TDL/CDL Z80 assembler. ; .pabs .phex .psym .xsym ; 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 & SIZE))) ; PAGEND equ (TOP > 8 ) & 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: lxi d,signon ;banner & prompt mvi c,9 call bdos call waitcr ;wait for CR ; mvi a,NITER ;set # iterations' more: push psw ; call primes pop psw dcr a jnz more ; lxi h,ANSWER ;verify answer dsbc b ;(cy clear) lxi d,donmsg jrz sayend ;Z - it's correct lxi d,badmsg sayend: mvi c,9 call bdos ; exit: lxi d,retmsg ;ask for CR again mvi c,9 ;..and exit to CCP call bdos ; waitcr: mvi c,6 ;wait mvi e,0ffh call bdos cpi CR jrnz waitcr mov e,a ;echo a CR mvi c,2 jmp bdos ; signon: db CR,LF .ascii "JetPrime Z80 -- BYTE Seive Benchmark - 10 iterations" retmsg: db CR,LF .ascii "Hit .$" ; donmsg: db CR,LF .ascii "1899 Primes$" ; badmsg: db CR,LF .ascii "Wrong!$" ; ; primes: lxi h,flags ;set all flags TRUE lxi d,flags+1 lxi b,SIZE mvi m,01h ldir ; ; initialize registers ;bc = count = 0 already mov d,b ;de = i = 0 mov e,b lxi h,flags ;&flags[0] exx ;bc' = &flags[0] lxi b,flags exx mvi a,PAGEND-1 ;last page of flags[] ; lp1: bit 0,m ;if flag[i] == TRUE jz next ; push d ;..set up for inner loop exx ;..& count this prime pop h ;hl' = i mov d,h ;de' = i mov e,l dad h ;*2 inx h inx h inx h ;+3 xchg ;de' = prime = i + i + 3, hl' = i dad d ;hl' = k = prime + i dad b ;hl' = &flag[k] ; lp2: cmp h ;while k <= SIZE jrc lp2x res 0,m ; flag[k] = FALSE dad d ; hl' = k = hl' + prime jmp lp2 ; lp2x: exx ;count the prime inx b ;count++ ; ; do next i ; next: inx h ;&keys[]++ inx d ;i++ cmp h jnc lp1 ret ;bc = count of primes ; ds (100h - (. & 00ffh)) free: ds 0 .end