flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > FOR Loop in FASM

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 142
Hi, first of all I apologize for asking "a lot" of questions these days, I hope it doesn't bother anyone Smile
So, my question day:
I tried to implement the for loop principle in FASM, here is my code:
Code:
format PE console
include 'C:\Users\mino\Desktop\fasmw172\stdlib.inc' ; contains '.idata'
entry main

section '.data' data readable writeable
        Hi   db "Hello", 10, 0
        inx  dw 1

section '.code' code executable
        main:
                push eax
                mov eax, ecx

        CL0:
                if inx <> 10
                   jmp LC0
                end if


                call [ExitProcess]
        LC0:
                push Hi
                call [printf]
                add [inx], 1
                jmp CL0
    

My code looks good to me. Besides, he's compiling. However, I must have forgotten something, because during the first iteration, it displays full of times "hello", then crashes.
Maybe it's the if instruction? I don't know about that.
I looked in the doc, but she doesn't seem to mention this kind of "mistake."

Could you help me Very Happy ?
Thank you, and have a good day!

_________________
The best way to predict the future is to invent it.
Post 17 Feb 2018, 10:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15912
Location: SDSS J140821.67+025733.2
if is an assembler directive. And inx is a fixed address that is never 10. So the result from if inx <> 10 is always true, thus the line jmp LC0 is always assembled and executed.

Perhaps you want to use cmp
Code:
  cmp [inx],10
  jb LC0
  call [ExitProcess]
LC0:    
Post 17 Feb 2018, 10:28
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 523
call [printf]
add esp,4 ;CDECL stack unwinding
Post 17 Feb 2018, 11:29
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 142
That's perfect, thank you very much for your help Smile

_________________
The best way to predict the future is to invent it.
Post 17 Feb 2018, 12:05
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-2018, Tomasz Grysztar.

Powered by rwasa.