Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Could use a little help...

Name: Vieo 2007-05-28 14:02 ID:1pOoiNCK

I have to hand in a prime number generator that will generate the first 500 primes as a project for school. It's due tomorrow, but he's giving us until Wednesday.

He prefers that we use Knuth's algorithm, but since I don't really get it, I want to try the brute force method. I wrote it in C++, then rewrote it with gotos to make it easier to translate into assembly.

Here it is:
==========================================
#include <iostream.h>

void main()
{
    int max=1000, n=2, i=0, j=0, count=0;

WLOOP: i = n;

FLOOP: if(n % i == 0)
           count++;
       i--;
       if(i >= 1)
           goto FLOOP;

       if(count == 2)
       {
           cout<<n<<" is prime."<<endl;
           j++;
       }
       n++;
       count = 0;

       if(j != max)
           goto WLOOP;
}
============================================

It generate's the 1,000th prime as 7919 so I know it works.


NOW, my problem lays in translating it into assembly. WE WERE supposed to use MASM, but for like the first half of the semester, we were stuck in a room that ran linux machines so we just messed around with MIXAL until I found a copy of MASM and gave it to the professor.

Anyway, the problem I'm having is this damn piece of shit is not working the way it's supposed to.

PROBLEM: For some reason when I move NUM to the AX register, even though I defined NUM as 2, SOME OTHER RANDOM SHIT appears in the AX register.

=====================================
        .MODEL SMALL
        .586
        .STACK 100H
        .DATA

MAX        DW 5
NUM         DW 2
INDEX        DW 0
MCOUNT    DW 0
QCOUNT    DW 0

MSG        DB    'EQUAL', 13, 10, '$'
MSG2        DB    'NOT EQUAL', 13, 10, '$'

        .CODE
MAIN        PROC


                MOV AX, NUM
================================================


See that code snippet above? What am I doing wrong. I am using Microsoft's CODEView debugger to follow what happens after each line is executed.

When MOV AX, NUM is run AX = 080C -- which is not a 2 !


Here is a screenshot: http://img408.imageshack.us/img408/8076/gdamnitlt7.jpg

Please help.

Name: Anonymous 2007-05-28 14:16 ID:tZ9N6OqS

>>5
also, you can put a return in a void function as well.
fucking piece of shit fuck you fuck

void __f(void) {
return;
}

shoop das whoop also, you dont make sense at all.


mov ax, [NUM]
WORKS.
fK
WTF DO YOU MEAN
FKFf

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List