flat assembler
Message board for the users of flat assembler.
Index
> Main > Program works, but slowly (beginner question) |
Author |
|
revolution 07 Feb 2020, 09:20
If we rewrite the python code then you might see the problem:
Code: n = 4 for i in range (n): for j in range(i+1,n): print ((i,j)) |
|||
07 Feb 2020, 09:20 |
|
aviv0404 07 Feb 2020, 11:48
revolution wrote: If we rewrite the python code then you might see the problem: Alright so I rewrote it and it's smooth now Code: ;unsigned: JA JB JAE JBE ;signed: JL JG JLE JGE format PE console entry start include 'win32a.inc' section '.text' code readable executable start: call read_hex mov edi, eax ; n mov esi, 0h ;i for loop 1 mov ecx, 0h ;j for loop 2 main_loop: for_1: mov ecx, esi inc ecx for_2: mov eax, esi call print_eax mov eax, ecx call print_eax ;increasing j and checking if its the end of the loop inc ecx cmp edi, ecx jg for_2 end_for_2: ;increasing i and checking if its the end of the loop inc esi cmp edi, esi jg for_1 end_for_1: end_process: push 0 call [ExitProcess] include 'training.inc' I still don't understand why the delay happened when the conditions where part of the code though |
|||
07 Feb 2020, 11:48 |
|
revolution 07 Feb 2020, 12:18
The problem is that you didn't reset the ECX counter inside loop1. So ECX spins all the way to 2^32 before wrapping back to zero.
|
|||
07 Feb 2020, 12:18 |
|
aviv0404 07 Feb 2020, 13:13
revolution wrote: The problem is that you didn't reset the ECX counter inside loop1. So ECX spins all the way to 2^32 before wrapping back to zero. Oh now I see it! The first loop was fine, ecx got to 4 and exit the loop but at the second loop it increased to 5 and then like you said there was a wraparound Thanks a lot! I took this concept for granted since I'm used to high level languages like python. I'll definitely pay attention to this in the future! |
|||
07 Feb 2020, 13:13 |
|
revolution 07 Feb 2020, 13:21
I highly recommend the use of a debugger. Especially a GUI debugger like Ollydbg. For beginners they can make things a lot clearer as you watch the execution process in action.
|
|||
07 Feb 2020, 13:21 |
|
aviv0404 07 Feb 2020, 13:55
revolution wrote: I highly recommend the use of a debugger. Especially a GUI debugger like Ollydbg. For beginners they can make things a lot clearer as you watch the execution process in action. Yeah a debugger will be really handy, I'll download Ollydbg right now! Thank you once more. |
|||
07 Feb 2020, 13:55 |
|
Tomasz Grysztar 07 Feb 2020, 14:05
You can find some basic tips on how to work with fasmw + OllyDbg in my video guides.
|
|||
07 Feb 2020, 14:05 |
|
aviv0404 07 Feb 2020, 14:42
Tomasz Grysztar wrote: You can find some basic tips on how to work with fasmw + OllyDbg in my video guides. Thanks, I'll definitely look into it! |
|||
07 Feb 2020, 14:42 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.