Re: The prodigal son returns...more easy Homework Help...



In data Mon, 19 Nov 2007 17:12:02 -0800 (PST), kuroikaze@xxxxxxxxx
scrisse:

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:

i have only a function that should says if a 32 bits number is prime
or not


; namsw -obj this.asm
; bcc32 -v this.obj
; but you have to change _sscanf_m and _P with sscanf and printf
section _DATA public use32 class=DATA

global _main
; int _sscan_m<(char** ove, char* input, char* fmt, ...)
extern _sscan_m , _P


_Numero_$$u$_non_primo$n db "Numero [%u] non primo" , 10 , 0
_Numero_$$u$_primo$n db "Numero [%u] primo" , 10 , 0


_Devi_inserire_il_numero_consentito_come_argomento$n
db "Devi inserire il numero consentito come argomento" , 10 , 0

___$u__ db "%u" , 0

section _TEXT public use32 class=CODE

; 0j, 4i, 8ra, 12PNum
isprime:
push esi
push edi
mov eax, [esp+12]
cmp eax, 1
ja .1
..0:
mov eax, 0
jmp short .f
..1:
cmp eax, 3
jbe .3
test eax, 0x1
jz .0
push eax
FILD dword [esp]
FSQRT
FISTP dword[esp]
pop edi
mov ecx, 3
mov esi, eax
xor edx, edx
add edi, 2
..2:
div ecx
cmp edx, 0
je .0
add ecx, 2
mov eax, esi
xor edx, edx
cmp ecx, edi
jbe .2
..3:
mov eax, 1
..f:
pop edi
pop esi
ret 4


; 0ra, 4Pargc, 8Pargv
_main:
mov eax, [esp+4]
cmp eax, 1
je .e
mov eax, [esp+8]
mov edx, [eax+4]
cmp edx, 0
je .e
; 0a, 4a
push eax
push eax
mov eax, esp
add eax, 4
mov ecx, esp
push ecx
push ___$u__
push edx
push eax
call _sscan_m
add esp, 16
mov ecx, [esp]
mov edx, eax
pop eax
pop eax
cmp edx, 1
jne .e
push ecx
push ecx
call isprime
pop ecx
cmp eax, 0
jne .1
push ecx
push _Numero_$$u$_non_primo$n
call _P
add esp, 8
jmp short .f
..1:
push ecx
push _Numero_$$u$_primo$n
call _P
add esp, 8
jmp short .f
..e:
push _Devi_inserire_il_numero_consentito_come_argomento$n
call _P
add esp, 4
..f:
xor eax, eax
ret

section _DATA public use32 class=DATA

global _main
/* int _sscan_m<(char** ove, char* input, char* fmt, ...)
extern _sscan_m, _P


"Numero [%u] non primo\n" db "Numero [%u] non primo", 10, 0
"Numero [%u] primo\n" db "Numero [%u] primo", 10, 0


"Devi inserire il numero consentito come argomento\n"
db "Devi inserire il numero consentito come argomento" , 10, 0

" %u " db "%u", 0

section _TEXT public use32 class=CODE

/* 0j, 4i, 8ra, 12PNum
isprime:
< i, j
a=[s+12];
a<=1!#.1
..0: a=0;#.f
..1: a<=3#.3
a&0x1!#.0
< a| FILD D [s]; FSQRT; FISTP D[s]| > j;
c=3; i=a; r^=r; j+=2;
..2: div c
r==0#.0
c+=2; a=i; r^=r; c<=j#.2;
..3: a=1
..f:
i, j
ret 4


/* 0ra, 4Pargc, 8Pargv
_main:
a=[s+4]; a==1#.e
a=[s+8]; r=[a+4];
r==0#.e
/* 0a, 4a
< a, a
a=s; a+=4; c=s;
_sscan_m<(a, r, " %u ", c)
c=[s]; r=a;
> a, a
r!=1#.e
< c| isprime(c)| > c
a==0!#.1| _P<("Numero [%u] non primo\n", c); #.f;
..1: _P<("Numero [%u] primo\n", c); #.f;
..e: _P<( "Devi inserire il numero consentito come argomento\n" )
..f:
a^=a
ret

.



Relevant Pages