Click to See Complete Forum and Search --> : Can someone help me out with this program please


Alopez69
April 18th, 2006, 10:31 PM
I have to write a program that will generate 100 prime numbers and print them 5 to a line I have done it without using procedures but when I tried to change it to use procedures its not working, any help would be appreciate it.

.DATA
hStdin DWORD ?
hStdout DWORD ?
written DWORD ?
read DWORD ?
file DWORD ?
forfile BYTE "Create a file name: ", 0
fname BYTE 20 DUP (?)
AR1 DWORD 100 DUP (?)
AR2 DWORD 100 DUP (?)
prompt BYTE "Last four digits of your ID/SS#: ", 0
ss4 DWORD 10 DUP (?)
get BYTE "Getting Prime Numbers ",cr, lf
primes Dword 11 DUP (?), cr, lf
index DWORD ?
lines DWORD ?

.CODE
GetPrimeNums Proc NEAR32
pushad
mov ecx,100
Loop1: inc esi
mov ebx, 2
Loop2: cmp ebx, esi
je IsPrime
mov eax, esi
mov edx, 0
div ebx
cmp edx, 0
je LOOP1
inc ebx
jmp Loop2
IsPrime: mov [edi],esi
add edi,2
dec ecx
cmp ecx,0
jne Loop1
popad
ret
GetPrimeNums ENDP

WritePrimeNums Proc NEAR32
pushad
mov ebx,lines
mov ebx,0
Loop3: mov eax, [edi]
add edi,2
dtoa Primes, eax
INVOKE WriteFile,
fname,
NEAR32 PTR Primes,
11,
NEAR32 PTR written,
0
inc ebx
cmp ebx, 5
jne lineExit
INVOKE WriteFile,
fname,
NEAR32 PTR Primes +11,
2,
NEAR32 PTR written,
0

lineExit: mov ecx,index
dec ecx
cmp ecx,0
jne Loop3
popad
ret
WritePrimeNums endp


_start:
INVOKE GetStdHandle,
STD_OUTPUT
mov hStdout, eax

INVOKE GetStdHandle, ;100
STD_INPUT
mov hStdin, eax

INVOKE WriteFile,
hStdout,
NEAR32 PTR forfile,
20,
NEAR32 PTR written,
0

INVOKE ReadFile,
hStdin,
NEAR32 PTR fname,
40,
NEAR32 PTR read,
0
mov ecx, read
mov BYTE PTR fname[ecx-2], 0

INVOKE CreateFileA,
NEAR32 PTR fname,
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
0,
0
mov file,eax

output Prompt
input SS4, 40
atod SS4
mov esi, eax
lea edi, AR1
call GetPrimeNums
INVOKE WriteFile,
file,
NEAR32 PTR get,
25,
NEAR32 PTR written, 0
call WritePrimeNums
output Prompt
input SS4, 40
atod SS4
mov esi, eax
lea edi, AR2
call GetPrimeNums
INVOKE WriteFile,
file,
NEAR32 PTR get,
20,
NEAR32 PTR written, 0
call WritePrimeNums

INVOKE CloseHandle,
file
INVOKE ExitProcess, 0

PUBLIC _start
END