err I meant: "Assembly for Intel based computers" by Kip Irvine
Posted on 2003-03-31 01:48:17 by locke
Ok. While it probably isn't related to your problem, you should get hold of hutch's masm32 package, as that's the includes most members here are using - this might avoid some problems later on. Also, the masm32 package (I _still_ think this is a silly name and is too easy to confuse with masm itself :rolleyes: ) has the most updated windows includes.

Your while loop is... "interesting" ;)
Posted on 2003-03-31 01:53:59 by f0dder
k, I'll check that out.

thanx :)
Posted on 2003-03-31 02:15:45 by locke
[B].code

main PROC

lea esi, buffer ;Load Effective Address buffer

mov al, 2 ;counter, should go from 2 to 9
mov dx, 1



.REPEAT

mov bl, 2
mul bl

.WHILE (ax < lengthof buffer)
push eax
mov ebx,esi
add eax,ebx ; <---- 32-bit values
mov esi,eax ; <----
add [esi], dx ; <----
pop eax
pop ebx
inc bl
mul bl
.ENDW

inc al

.UNTIL(al >= 10)
[/B]
According to the posted code, you set only 8 bits (AL) at the start of this loop. The multiply provides 16 valid bits. But there is no guarantee that the upper 16 bits are zeros. Fixing this may solve the addressing problem because the processor is using 32 bits (ESI) for addressing.

The easiest way is to start the loop with

mov eax,2 ; ***** make sure we know what's in all 32 bits of EAX
Posted on 2003-03-31 17:29:51 by tenkey
The algo looks fine, however this is "pure" sieve, and you might want to look into some of the variants on this algo which are set up to perform more efficient searches, ranged searches, etc. I am assuming that your goal is to generate Giant Primes, not simply find prime numbers...
Posted on 2003-03-31 20:53:35 by Homer
With the help of a friend (Scrots), updated the code ... although slow, it's working!

=====================================================================

; #########################################################################
.386 ; minimum processor needed for 32 bit
.model flat, stdcall ; FLAT memory model & STDCALL calling
option casemap :none ; set code to case sensitive

; #########################################################################

; ---------------------------------------------
; main include file with equates and structures
; ---------------------------------------------
include \masm32\include\windows.inc

include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


; #########################################################################

num65000 EQU 65000

; #########################################################################

.data
szoutputfilename db "text.txt" , 0
dwbyteswritten dd 0
hOutputFile dd 0

szMyString db 128 DUP (0)
buffer db num65000 DUP (0)
sztemplate db "%d",13,10,0

; #########################################################################

.code

start:

invoke CreateFile, ADDR szoutputfilename, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL

mov hOutputFile, eax


invoke RtlZeroMemory, offset buffer, num65000

;unsigned int a[65000];
;for(unsigned int counter=0;counter<65000;counter++)
; a=0;
;
; unsigned int a[65000];
; for (counter=2;counter<10;counter++){
; unsigned int rotation=2,position=0;
; while ((position=rotation*counter)<65000){
; a=1;
; rotation++;
; }
; }
;
;for(counter=0;counter<100;counter++)
; if (a==0) cout<<endl<<counter<<" : "<<a;
;
;return 0;


; fill buffer with primes
push edi
lea edi,buffer

mov ecx, 0
startloop:
push ecx
mov byte ptr ,0

mov eax,2
mov ecx,2
innerloop:
push ecx

mov edx, 2 ; rotation
@@:
push edx
mov eax, ecx
mul edx
pop edx
cmp eax, 65000
jae @F
mov byte ptr ,1
inc edx
jmp @B
@@:

pop ecx
inc ecx
cmp ecx, 10
jne innerloop


pop ecx
inc ecx
cmp ecx, num65000
jne startloop

mov byte ptr ,1
mov byte ptr ,1


pop edi

; print out the primes
push edi

lea edi,buffer
mov ecx,0
printloop:
push ecx

xor eax, eax
mov al, byte ptr
cmp eax, 0
jne @F
invoke wsprintf, ADDR szMyString, ADDR sztemplate, ecx
invoke lstrlen, ADDR szMyString
invoke WriteFile, hOutputFile, ADDR szMyString, eax, ADDR dwbyteswritten, 0
@@:

inc edi

pop ecx
inc ecx
cmp ecx, num65000
jne printloop



pop edi

invoke CloseHandle, hOutputFile
invoke ExitProcess, NULL
end start
Posted on 2003-04-03 13:56:53 by locke