From: kuroikaze on
So yeah I'm still doing various flavors of finding prime numbers.

Assignment 4 was to find 20 primes, put them into an array, and then
output them to a file in a recursive loop. Easy.

Assignment 5 is to break things into procedures, and do 20 higher and
30 lower primes from the input number. Sounds easy? For some reason
it's not.

I have a higher prime array and a lower prime array.
My code is rapidly turning to trash as I continually make changes to
try and get some semblance of good output.

I was supposed to use push/pop commands for things but I've removed
them to see if I could get the code to work right.

The output I'm getting looks like this:

------------------------------------------------------------------
This is your original number: 1234

Here are your larger prime numbers:

1237
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Here are your smaller prime numbers:

1231
0
0
0
0
0
0
0
0
0
1237
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

As you can see my array are totally misfiring or being referenced in a
bad way no matter what I come up with.

I'll put the code in the next post.
From: kuroikaze on

; Find Prime Numbers and output file

;================================================

..386
..MODEL FLAT

STD_OUTPUT EQU -11
cr EQU 0dh
Lf EQU 0ah
pNumsUpMax EQU 20
pNumsDwnMax EQU 30
GENERIC_WRITE EQU 40000000h
CREATE_ALWAYS EQU 2


ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h

GetStdHandle PROTO NEAR32 STDCALL, nStdHandle:DWORD

WriteFile PROTO NEAR32 stdcall,
hFile:DWORD, lpBuffer:NEAR32, nNumberOfCharsToWrite:DWORD,
lpNumberOfBytesWritten:NEAR32, lpOverlapped:NEAR32

CreateFileA PROTO NEAR32 stdcall,
lpFileName:NEAR32, access:DWORD, shareMode:DWORD,
lpSecurity:NEAR32, creation:DWORD, attributes:DWORD,
copyHandle:DWORD

CloseHandle PROTO NEAR32 stdcall,
fHandle:DWORD

;================================================

..STACK 4096

..DATA

numIn WORD ?
pNumsUp WORD pNumsUpMax DUP (?)
pNumsDown WORD pNumsDwnMax DUP (?)
prompt1 BYTE "Please enter a four digit integer: "
promptLng DWORD 39
string BYTE 6 DUP (?), 0
hStdOut DWORD ?
written DWORD ?
tester WORD ?
primeCtr BYTE ?
nbrElts BYTE 0
fileName BYTE "Assignment05.txt"
hFile DWORD ?
read DWORD ?
buffer BYTE 6 DUP (?), cr, Lf
origPrompt BYTE "This is your original number: "
origLng DWORD 31
primePrompt BYTE cr, Lf, "Here are your larger prime numbers: ", cr,
Lf, cr, Lf
primeLng DWORD 43
primePrompt2 BYTE cr, Lf, "Here are your smaller prime numbers: ",
cr, Lf, cr, Lf
primeLng2 DWORD 44
store1 DWORD ?
store2 DWORD ?
teststring BYTE cr, Lf, 11 DUP (?), 0, cr, Lf
checker BYTE ?
arrayCounter BYTE ?

;================================================

..CODE

GetInputNum PROC NEAR32

INVOKE GetStdHandle, STD_OUTPUT
mov hStdOut, eax

INVOKE WriteFile,
hStdOut,
NEAR32 PTR prompt1,
promptLng,
NEAR32 PTR written,
0

input string, 6
atoi string
mov numIn, ax
Ret

GetInputNum EndP

;================================================

GetPrimeNums PROC NEAR32

mov ax, numIn
mov tester, ax

nextNum:

mov cx, 2
; pop dx
; cmp dh, 1
cmp checker, 1
je higher
jmp lower

higher:
; push dx
inc tester
jmp primeTest

lower:
; push dx
dec tester
jmp primeTest

primeTest:

mov ax, tester
cmp ax, cx
je foundPrime
mov dx, 0
div cx
cmp dx, 0
je nextNum
inc cx
jmp primeTest

foundPrime:

mov [ebx], eax
inc nbrElts
cmp nbrElts, dl
je allDone
add ebx, 4
jmp nextNum

allDone:
; push ebx
cmp checker, 1 ; fix?
je save1 ; fix?
mov store2, ebx ; fix?
Ret

save1: ; fix?
mov store1, ebx ; fix?
Ret ; fix?

GetPrimeNums EndP

;================================================

WritePrimeNums PROC NEAR32

;pop ebx

arrayOutput:

; dec dl
dec arrayCounter
; push dx
mov eax, [ebx]
itoa buffer, ax

INVOKE WriteFile,
hFile,
NEAR32 PTR buffer,
8,
NEAR32 PTR written,
0

; pop dx
cmp arrayCounter, 0
je allDone
sub ebx, 4
jmp arrayOutput

allDone:
Ret

WritePrimeNums EndP


;================================================

_start:

call GetInputNum

mov nbrElts, 0
lea ebx, pNumsUp
mov dl, 20
mov dh, 1
push dx
mov checker, 1
call GetPrimeNums

mov nbrElts, 0
lea ebx, pNumsDown
mov dl, 30
mov dh, 0
push dx
mov checker, 2
call GetPrimeNums

;================================================

INVOKE CreateFileA,
NEAR32 PTR fileName,
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
0,
0
mov hFile, eax

mov ax, numIn
itoa buffer, ax

INVOKE WriteFile,
hFile,
NEAR32 PTR origPrompt,
origLng,
NEAR32 PTR written,
0

INVOKE WriteFile,
hFile,
NEAR32 PTR buffer,
8,
NEAR32 PTR written,
0

INVOKE WriteFile,
hFile,
NEAR32 PTR primePrompt,
primeLng,
NEAR32 PTR written,
0

;================================================

;lea ebx, pNumsUp
mov ebx, store1 ; fix?
mov edx, 0
;mov dl, 20
mov arrayCounter, 20

call WritePrimeNums

INVOKE WriteFile,
hFile,
NEAR32 PTR primePrompt2,
primeLng2,
NEAR32 PTR written,
0


;lea ebx, pNumsDown
mov ebx, store2 ; fix?
mov edx, 0
;mov dl, 30
mov arrayCounter, 30

call WritePrimeNums


;================================================

INVOKE CloseHandle, hStdOut
INVOKE ExitProcess, 0

PUBLIC _start
END


;dtoa teststring, eax
;INVOKE WriteFile,
; hStdOut,
; NEAR32 PTR teststring,
; 16,
; NEAR32 PTR written,
; 0
;
;dtoa teststring, ebx
;INVOKE WriteFile,
; hStdOut,
; NEAR32 PTR teststring,
; 16,
; NEAR32 PTR written,
; 0
;
;dtoa teststring, ecx
;INVOKE WriteFile,
; hStdOut,
; NEAR32 PTR teststring,
; 16,
; NEAR32 PTR written,
; 0
;
;itoa teststring, dx
;INVOKE WriteFile,
; hStdOut,
; NEAR32 PTR teststring,
; 16,
; NEAR32 PTR written,
; 0
From: Phil Carmody on
kuroikaze(a)gmail.com writes:
> So yeah I'm still doing various flavors of finding prime numbers.
>
> Assignment 4 was to find 20 primes, put them into an array, and then
> output them to a file in a recursive loop. Easy.

'recursive' and 'loop' clash with each other.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration
From: kuroikaze on
On Nov 19, 7:53 pm, Phil Carmody <thefatphil_demun...(a)yahoo.co.uk>
wrote:
> kuroik...(a)gmail.com writes:
> > So yeah I'm still doing various flavors of finding prime numbers.
>
> > Assignment 4 was to find 20 primes, put them into an array, and then
> > output them to a file in a recursive loop. Easy.
>
> 'recursive' and 'loop' clash with each other.
>
> Phil
> --
> Dear aunt, let's set so double the killer delete select all.
> -- Microsoft voice recognition live demonstration

Doh. So any idea about the actual question? : )
From: Phil Carmody on
kuroikaze(a)gmail.com writes:
> On Nov 19, 7:53 pm, Phil Carmody <thefatphil_demun...(a)yahoo.co.uk>
> wrote:
> > kuroik...(a)gmail.com writes:
> > > So yeah I'm still doing various flavors of finding prime numbers.
> >
> > > Assignment 4 was to find 20 primes, put them into an array, and then
> > > output them to a file in a recursive loop. Easy.
> >
> > 'recursive' and 'loop' clash with each other.
>
> Doh. So any idea about the actual question? : )

If you were told to do something that doesn't make sense, then
the obvious thing is to do something that doesn't make sense.

Maybe you'll get full marks for wearing a Chubacka costume to
all your classes from now on?

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration
 |  Next  |  Last
Pages: 1 2 3 4 5
Prev: BIOS setting
Next: AMD adds Skybuck's Instruction LOL.