flat assembler
Message board for the users of flat assembler.

Index > Windows > Hey!

Author
Thread Post new topic Reply to topic
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 Smile
thanks!
Post 10 Jun 2009, 16:04
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
Madis731



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

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


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


Change the code to:
Code:
  xor eax,eax
  mov ecx,10
@@:
  dec ecx
  add eax,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 Smile

To board advanced members: I was bored, otherwise I would've linked to some tutorial Razz
Post 10 Jun 2009, 19:05
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
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?
Post 10 Jun 2009, 19:50
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
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
Post 10 Jun 2009, 20:37
View user's profile Send private message Reply with quote
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
Post 10 Jun 2009, 21:09
View user's profile Send private message Reply with quote
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.
Post 10 Jun 2009, 21:18
View user's profile Send private message Reply with quote
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
Post 11 Jun 2009, 00:20
View user's profile Send private message Reply with quote
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.
Post 11 Jun 2009, 01:56
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
sorry, I replaced prefix with suffix, my mistake. It's the b suffix.
Post 11 Jun 2009, 03:07
View user's profile Send private message Reply with quote
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!
Post 11 Jun 2009, 11:50
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
kdownload



Joined: 31 Oct 2008
Posts: 18
kdownload
Code:
  xor eax,eax
  mov ecx,10
@@:
  inc eax
  loop @b     
Post 11 Jun 2009, 15:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.