Jeśli chcesz wziąć udział w dyskusjach na forum - zaloguj się. Jeżeli nie masz loginu - poproś o członkostwo.
Vanilla 1.1.4 jest produktem Lussumo. Więcej informacji: Dokumentacja, Forum.
org $2000
.var time .word
.var i,b,radius,n .word = $80
.var fac1,fac2 .byte = $e0
.var result .word =$e0
mwa #16129 radius
mwa #0 i
mwa #0 b
wait
mwa #0 $13
loop #while .word i < #10000
inw i
lda $d20a
and #$7f
sta fac1
sta fac2
imulCL
mwa result n
lda $d20a
and #$7f
sta fac1
sta fac2
imulCL
adw n result
sbw n radius
bcs loop
inw b
#end
mva #0 n
lda b+1
sta fac1
lda #4
sta fac2
imulCL
mva result n+1
lda b
sta fac1
lda #4
sta fac2
imulCL
adw n result
mva $14 time
mva $13 time+1
jsr printf
.by 'pi %',$1e,$1e,$1e,$1e,$ff,$2c,$9b
.by 'fps % ',$9b,0
dta a(n)
dta a(time)
jmp *
.proc wait
lda:cmp:req $14
rts
.endp
.proc imulCL
ldy #8
lda #0
lsr fac1
@L0: bcc @L1
clc
adc fac2
@L1: ror @
ror fac1
dey
bne @L0
sta fac2
rts
.endp
.link 'printf.obx'
; 8x16 routine with external entry points used by the 16x16 routine in mul.s
tosmula0:
tosumula0:
sta ptr4
mul8x16:jsr popptr1 ; Get left operand (Y=0 by popptr1)
tya ; Clear byte 1
ldy #8 ; Number of bits
ldx ptr1+1 ; check if lhs is 8 bit only
beq mul8x8 ; Do 8x8 multiplication if high byte zero
mul8x16a:
sta ptr4+1 ; Clear byte 2
lsr ptr4 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptr1
tax
lda ptr1+1 ; hi byte of left op
adc ptr4+1
sta ptr4+1
txa
@L1: ror ptr4+1
ror a
ror ptr4
dey
bne @L0
tax
lda ptr4 ; Load the result
rts
; 8x8 multiplication routine
mul8x8:
lsr ptr4 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptr1
@L1: ror
ror ptr4
dey
bne @L0
tax
lda ptr4 ; Load the result
rts ; Done
;while
jmp test_warunku
while_loop
...
...
..
test_warunku
if i < 10000 then
goto whileloop
else
wyjscie z petli WHILE
/*
;
; Ullrich von Bassewitz, 2009-08-17
;
; CC65 runtime: 8x8 => 16 unsigned multiplication
;
*/
.proc imulCL
ptr1 = ecx
ptr4 = eax
ldy #8
lda #0
lsr ptr4 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptr1
@L1: ror @
ror ptr4
dey
bne @L0
sta ptr4+1
rts
.endp
.proc imulCL
lda #$00
LDY #$09
CLC
LOOP ROR @
ROR eax
BCC MUL2
CLC ;DEC AUX above to remove CLC
ADC ecx
MUL2 DEY
BNE LOOP
STA eax+1
RTS
.endp
#include <stdio.h>
#include <string.h>
#define true 1
#define false 0
#define size 8190
#define sizepl 8192
unsigned char flags[sizepl];
unsigned char is_prime(unsigned int n)
{
register unsigned int i;
for (i = 2; i <= n / 2; ++i)
{
// condition for non-prime
if (n % i == 0)
return 0;
}
return 1;
}
int main()
{
register unsigned int i, prime, k, count;
memset(flags, true, sizeof(flags));
for (i=0;i<=size;++i)
{
if (flags[i])
{
prime = i*2 + 3;
k = i + prime;
while (k <= size) {
flags[k] = false;
k += prime;
}
++count;
}
}
i=3; // starting from 3
for (prime=0;prime<=size;++prime)
{
printf("Num %d by 'fake':%d, real:%d\n", i, (int) flags[prime], is_prime(i));
i+=2;
}
inf:
goto inf;
return 0;
};
/* Eratosthenes Sieve benchmark */
#include <peekpoke.h>
#include <stdio.h>
#include <string.h>
#define true 1
#define false 0
#define size 8190
#define sizepl 8192
#define tick 0x14
#define tack 0x13
unsigned char flags[sizepl];
void wait(void)
{
unsigned char a=PEEK(tick);
while (PEEK(tick)==a) { ; }
}
int main()
{
register unsigned int i, prime, k, count, iter;
wait();
printf("10 iterations\n");
asm(" lda #0");
asm(" sta $13");
asm(" sta $14");
for (iter = 1 ; iter <= 10; ++iter)
{
count = 0;
memset(flags, true, sizeof(flags));
for (i=0;i<=size;++i)
{
if (flags[i]) {
prime = i*2 + 3;
k = i + prime;
while (k <= size) {
flags[k] = false;
k += prime;
}
++count;
}
}
}
i=PEEK(0x14)+PEEK(0x13)*256;
printf("%d primes\n", count);
printf("%d ticks\n", i);
asm(" jmp *");
return 0;
}
// Eratosthenes Sieve Benchmark
uses crt;
{$define FAST}
const
size = 16380;
sqr_count = 128;
var
flags: array [0..size] of boolean;
rtClock: byte absolute $14;
{$ifdef FAST}
n: word absolute $e0;
k: word absolute $e2;
count: word absolute $e6;
{$else}
n, k, count: word;
{$endif}
begin
writeln('Mad Pascal');
writeln('Eratosthenes Sieve Benchmark');
rtClock := 0;
fillchar(flags, sizeof(flags), true);
for n := 2 to sqr_count do begin
if flags[n] then begin
k := n shl 1;
while k <= size do begin
flags[k] := false;
Inc(k,n);
end;
end;
end;
writeln(rtClock, ' ticks');
count :=0;
for n := 2 to size do begin
if flags[n] then Inc(count);
end;
writeln(count, ' primes');
repeat until keypressed;
end.
kosa0:
W zwiazku ze sie nieznam to sie wypowiem :-)