News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Need A little bit of help

Started by allen, February 24, 2014, 04:47:40 PM

Previous topic - Next topic

GoneFishing

I found MS VS C++ sample PRIMESSTEP2 (mixed C and ASM)
Stepped through the asm code line by line  - it's perfect  :t
I've even generated 262144 byte raw file ( for visualization in 512x512 window )
(If anyone is interested in results - let me know and I'll post it)

allen

#16
Thanks everyone i just stick to my first simple broken code even i get  C- this semester it was eye opening experience masm  is truly hard. Thanks you guys were a big help and letting me understand masm better than my professor who lack to teach us anything just write down the all the instruction without discussing or explain to us what it does and give us 10 program to write the prime number. for me is the most hardest for me.because I totally failed at and MATH class and mostly i just copy from my friends when it comes to MATH

dedndave

it's actually not that hard
there is just a lot of material to absorb   :P

MDWLibby

Hi All

I'm new, (this is my 1st post).  Allen it seems is about to give up.  I hope no!  I to am just learning Asm.  It takes courage to post code and ask questions.  You people do well at helping the brave beginner, and I'm sure in the not to distant future I'll be posting my own questions and code.  I'm an old hack, the 1st time I was called a "Hacker", I took it as an insult.  In the last 6 months I have had to do much reading.  I'm from the days of Dos and MASM, that was back some 25 years ago.  I have done a little hobby programing in Power Basic in the last 10 years, and have decided to stretch out.  After 2 - 3 weeks of looking at Assemblers, I think I might have looked at all of them.  I have visited these Forum many times, and is one of the many reasons I have decided to use MASM again.

Thanks Allen for having the courage to ask.  Whether you stick to it or not, you have already help teach, (something your professor seams to lack).

Thanks All

Gunther

Hi MDWLibby,

thank you for your courageous words and welcome to the forum.

Gunther
You have to know the facts before you can distort them.

GoneFishing

#20
 Shame on me  :icon_redface:
Today I ran the code posted in my Reply#6 and suddenly discovered that numbers 9 ,15, 21 are listed as prime ones. I figured out that it was because of incorrect use of REPEAT - UNTIL  block:
Quote
                   mov ecx, 2

.REPEAT
     @@:         
                   xor edx,edx
                   mov eax,num
                   div ecx
                   .if edx == 0          ; if the remainder is zero
                       mov PRIME, FALSE  ; the flag is cleared
                   .endif
                   inc ecx
                   cmp ecx,num
                   jnz @B     

     .UNTIL ecx <= num - 1

P.S.: thank you guys that you were so polite and didn't  point  to my silly error   :t
   

jj2007

Interesting that neither MASM nor JWasm throw an error or at least a warning. In the disassembly, you can see that ecx <= num - 1 encodes as .UNTIL ecx <= num[-1] - which is clearly a different animal.

In contrast,

For_ ecx=0 To eax-1
   nop
Next

is entirely legal ;-)

GoneFishing

Quote from: jj2007 on March 10, 2014, 03:40:41 AM
...
In the disassembly, you can see that ecx <= num - 1 encodes as .UNTIL ecx <= num[-1] - which is clearly a different animal.
...
Seems so .
Quote
00401074                    loc_00401074:               ; Xref 0040106B
00401074 41                     inc     ecx
00401075 3B0DFF2F4000           cmp     ecx,[off_00402FFF]
0040107B 77E3                   ja      loc_00401060

from WinDbg session:

; num = 3
00401076 3b0dff2f4000    cmp     ecx,dword ptr [image00400000+0x2fff (00402fff)] ds:002b:00402fff=00000300
; num = 5
00401076 3b0dff2f4000    cmp     ecx,dword ptr [image00400000+0x2fff (00402fff)] ds:002b:00402fff=00000500
; num = 7
00401076 3b0dff2f4000    cmp     ecx,dword ptr [image00400000+0x2fff (00402fff)] ds:002b:00402fff=00000700



This version works too :
Quote
.REPEAT           
                   xor edx,edx
                   mov eax,num
                   div ecx
                   .if edx == 0          ; if the remainder is zero
                       mov PRIME, FALSE  ; the flag is cleared
                   .endif
                   inc ecx
.UNTIL ecx == num  

jj2007

By the way,
   .if edx==0
is one byte longer than
   .if !edx

GoneFishing