flat assembler
Message board for the users of flat assembler.

 Index > Windows > Hey!
Author
Dreamz

Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
Now i know i have asked like a ton of stupid Qs, lol
i would just like to know where i could just get started? like a tutorial or a good eBook with examples the work and are expplained
thanks!
10 Jun 2009, 16:04

Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Try a loop

C-language:
Code:
```int sum=0;
for(int x=0;x<10;x++)
{
sum+=x;
}
```

ASM:
Code:
```  xor eax,eax
xor ecx,ecx
@@:
cmp ecx,10
jl @b
```

Change the code to:
Code:
```  xor eax,eax
mov ecx,10
@@:
dec ecx
test ecx,ecx
jz @b
```

Now think why these two codes are identical, the result I mean. Prove that it is so (or prove that its not) and come back here

To board advanced members: I was bored, otherwise I would've linked to some tutorial
10 Jun 2009, 19:05
Dreamz

Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
thanks!
well.... hmm...
if the 10 is binary... then that means its 2...er...a..
lol this is hard...
i can c the differences(the two asm codes right?).....
the 10 is being stored in ecx i guess...
i give up lol, wat?
10 Jun 2009, 19:50
IronFelix

Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Hi, guys!
Some same code (less in size) with a little bit comments:
Code:
```  xor eax,eax ; zero register with result
mov ecx,9 ; initialize loop counter with (10 - 1)
@@: ; <- anonymous label
add eax,ecx ; add loop counter to result
dec ecx ; decrement loop counter
js @b ; <- jump to nearest upper anonymous label if sign bit is set (if got negative result in loop counter, in our case -1)     ```

Regards
10 Jun 2009, 20:37
pal

Joined: 26 Aug 2008
Posts: 227
pal
Dreamz I was bored also so.

The two codes are not equal. 10 is in decimal (not binary).

The first code (asm one that is) will do exactly what the C code does. Increment ecx until it is equal to 10, adding the value of ecx to eax.

The second code will start with ecx as being 10. It will then add the ecx value to eax. It then checks if ecx is zero and if it is goes back. The second code doesn't make a huge amount of sense as it is not actually a loop when you look at it. Maybe it was meant to be jnz @B? And also for IronFelix as jns @B or the same.

Edit: Make it more readable. Also wtf site is slow... DDoS again?

Last edited by pal on 10 Jun 2009, 21:58; edited 3 times in total
10 Jun 2009, 21:09
IronFelix

Joined: 09 Dec 2004
Posts: 141
Location: Russia, Murmansk region
IronFelix
Oh, yes, of course you are right, pal! - "js @b" should be "jns @B" in my code or even "jnz @B" in order not to add zero to "eax" and exclude unneccessary iteration. Sorry for this mistake - i didn't pay enough attention.
10 Jun 2009, 21:18
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Dreamz wrote:
if the 10 is binary...
NO it's decimal.
If you want binary, in FASM you use the b suffix.

e.g: 10b

would be 2

_________________
Previously known as The_Grey_Beast

Last edited by Borsuc on 11 Jun 2009, 03:07; edited 1 time in total
11 Jun 2009, 00:20
bitshifter

Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
There is a small fasm tutorial at the bottom of this page...
http://flatassembler.net/docs.php

This was the first one i learned.
Then you should read the fasm manual about 40 times.
Im serious, i have read it that many times and still have not mastered it.
Learning to program and learning a syntax are two different things.
Keep this in mind since any language can teach you how to program.
11 Jun 2009, 01:56
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
sorry, I replaced prefix with suffix, my mistake. It's the b suffix.
11 Jun 2009, 03:07
Dreamz

Joined: 10 Apr 2009
Posts: 25
Location: US
Dreamz
IronFelix wrote:
Hi, guys!
Some same code (less in size) with a little bit comments:
Code:
```  xor eax,eax ; zero register with result
mov ecx,9 ; initialize loop counter with (10 - 1)
@@: ; <- anonymous label
add eax,ecx ; add loop counter to result
dec ecx ; decrement loop counter
js @b ; <- jump to nearest upper anonymous label if sign bit is set (if got negative result in loop counter, in our case -1)     ```

Regards

pal wrote:
Dreamz I was bored also so.

The two codes are not equal. 10 is in decimal (not binary).

The first code (asm one that is) will do exactly what the C code does. Increment ecx until it is equal to 10, adding the value of ecx to eax.

The second code will start with ecx as being 10. It will then add the ecx value to eax. It then checks if ecx is zero and if it is goes back. The second code doesn't make a huge amount of sense as it is not actually a loop when you look at it. Maybe it was meant to be jnz @B? And also for IronFelix as jns @B or the same.

Edit: Make it more readable. Also wtf site is slow... DDoS again?

bitshifter wrote:
There is a small fasm tutorial at the bottom of this page...
http://flatassembler.net/docs.php

This was the first one i learned.
Then you should read the fasm manual about 40 times.
Im serious, i have read it that many times and still have not mastered it.
Learning to program and learning a syntax are two different things.
Keep this in mind since any language can teach you how to program.

Thanks all! i will try that, i was afraid id hav to read it alot, i hav only read part of it lol.
thanks so much!
11 Jun 2009, 11:50

Joined: 31 Oct 2008
Posts: 18
Code:
```  xor eax,eax
mov ecx,10
@@:
inc eax
loop @b     ```
11 Jun 2009, 15:16
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum