flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Madis731 10 Jun 2009, 19:05
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 @@: 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 ![]() To board advanced members: I was bored, otherwise I would've linked to some tutorial ![]() |
|||
![]() |
|
Dreamz 10 Jun 2009, 19:50
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? |
|||
![]() |
|
IronFelix 10 Jun 2009, 20:37
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 10 Jun 2009, 21:09
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 |
|||
![]() |
|
IronFelix 10 Jun 2009, 21:18
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.
|
|||
![]() |
|
Borsuc 11 Jun 2009, 00:20
Dreamz wrote: if the 10 is binary... 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 |
|||
![]() |
|
bitshifter 11 Jun 2009, 01:56
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. |
|||
![]() |
|
Borsuc 11 Jun 2009, 03:07
sorry, I replaced prefix with suffix, my mistake. It's the b suffix.
|
|||
![]() |
|
Dreamz 11 Jun 2009, 11:50
IronFelix wrote: Hi, guys! pal wrote: Dreamz I was bored also so. bitshifter wrote: There is a small fasm tutorial at the bottom of this page... 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! |
|||
![]() |
|
kdownload 11 Jun 2009, 15:16
Code: xor eax,eax mov ecx,10 @@: inc eax loop @b |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.