My program wasn't working, so I began outputing at different stages to see what was going on. I take 100 and div by 2. It does get 50. A little bit later, it is still 50, but then, it's 3. It continues, 50, 50, 4, 50, 50, 5,...,50, 50, 50, 50, 1. I don't want it to change at all. I said screw the division, I will hard code 50 in, but it still changes.

The only thing I really do is mov eax, themover. themover is two, then three, and so on. Why is that affecting onehalf?


primearr BYTE 100 DUP(0)
onehalf DWORD 50 ;;;;;;;This is what changes
lastcheck DWORD 2
themover DWORD 2
theprime BYTE 3 dup(' '),0

;mov eax, lengthof primearr ;Get length of the array
;mov edx, 0 ;For Division
;mov ebx, 2 ;Move 2 to bl for division
;div ebx ;Divide to know when to stop
;mov onehalf, eax ;Store in OneHalf
mov edi, offset primearr ;Get address of primearr

mov edi, 2 ;Make edi 2, the first prime

addagain: mov eax, themover ;Move the prime for multiples

mov eax, onehalf ;;;;;;;output for testing
dtoa theprime, eax;;;;;;this is where it changes
output theprime

add edi, eax ;Go to first prime, move by multiples of the prime
cmp edi, lengthof primearr ;check if x is bigger than the array
JA incagain ;if if it is
mov primearr[edi], 1 ;x is not prime, divisible by x
jmp addagain ;Keep going to end of array
Posted on 2004-10-07 00:01:56 by sjaguar13
What is dtoa and output? Maybe those marcos corrupt the values in the registers.
Posted on 2004-10-07 00:07:32 by roticv
dtoa is decimal to ascii. It takes eax and converts it to ascii in theprime. Output just sends it to the screen. I use those all the time in my programs.
Posted on 2004-10-07 00:17:07 by sjaguar13
I don't understand your code at all. You first make edi point to primearr, then you overwrite it immediately with 2?!

one of the things that can occur (nobody can say anything about your code because we can't see your macro's and such, so i can only guess) is that primearr is too small and that onehalf gets overwritten when primearr is full.
Posted on 2004-10-07 12:30:53 by lifewire
Where's the label "incagain"?
Posted on 2004-10-07 22:08:11 by AmkG
That's wasn't the full code.

The good news is, I got it to work. Thanks everybody!
Posted on 2004-10-07 22:12:51 by sjaguar13