assembly - MASM Calculating Composites -


i trying run code asks user input between 1 , 400 , gives number of composites. ex. input of 31 yield 4 6 8 9 10 12 14 15 16 18 20 21 22 24 25 26 27 28 30 32 33 34 35 36 38 39 40 42 44 45 46

the following code crashes when attempt run it:

        userint1    dword   ?           ;integer entered user     userint2    dword   ?           ;integer entered user     intro_1     byte    "composite numbers  by. eric walters" , 0     prompt_1    byte    "enter number of composite numbers see. ", 0     prompt_2    byte    "i'll accept orders 400 composites. ", 0     prompt_3    byte    "enter number of composites display [1 .. 400]: ", 0     prompt_4    byte    "test", 0     prompt_6    byte    "results certified eric walters.",0     prompt_7    byte    "goodbye, ", 0     outofrange  byte    "out of range. try again.",0     goodbye     byte    "impressed? bye! ", 0     upperlevel  dword   400         ;the largest integer allowed     lowerlevel  dword   1           ;the smallest integer allowed     newarray    dword   500 dup(?)   .code main proc  push    offset newarray push    ebp mov     ebp,esp mov     esi,[ebp + 8]   ; introduction        mov     edx, offset intro_1     call    writestring     call    crlf     call    crlf     mov     edx, offset prompt_1     call    writestring     call    crlf     mov     edx, offset prompt_2     call    writestring     call    crlf     call    crlf  ; getuserdata     userprompt:         mov     edx, offset prompt_3         call    writestring         call    readint         mov     userint1, eax         mov     eax, userint1      ;validate            cmp     eax, upperlevel         ja      option1         cmp     eax, lowerlevel         jb      option1         jmp     option2      option1 :         mov     edx, offset outofrange         call    writestring         call    crlf         jmp     userprompt      mov     ecx, 4     option2 :         cmp     ecx, userint1         jnle    done         mov     ebx, 2        showcomposites :         mov     edx, ecx         sub     edx, 1         cmp     ebx, edx         jge     l1         mov     eax, ecx         div     ebx         cmp     edx, 0         je      composite      resume :         inc     ebx         jmp     showcomposites      l1:         inc     ecx         jmp     option2      done :         pop     ebp         ret     4      composite:         mov     [esi], ecx         add     esi, type dword         jmp     l1  ; farewell     mov     edx, offset prompt_6     call    writestring     call    crlf     mov     edx, offset prompt_7     call    writestring     call    crlf       exit        ; exit operating system main endp  end main 

any appreciated!

assuming did not fail assemble exe extrn/public declarations in order.

jmp     userprompt  mov     ecx, 4           ;useless code?  option2 : cmp     ecx, userint1    ;not understanding when ecx initialized , jnle    done             ;why, suppose above code mov     ebx, 2           ;that misplaced? 

this part threw me off , don't understand algorithm sequential composite numbers.

here's idea: why not set array of 1-400 composite numbers , have user input between 1-400 loop counter loop display each array element? (not efficient on time , memory algorithm though.)


Comments