Jump to content

[ASMx86] Is there any point in using loop commands over jumps?

Noirgheos

Recently completed a project for school, and used compare and various jump commands to get it done. While it worked without issue, my instructor said using loop commands would shorten it a decent bit. Thing is, loop commands have what... three conditions? Not to mention the loop distance limit. How could it shorten code?

i7 6700K @ Stock (Yes I know) ~~~ Corsair H80i GT ~~~ GIGABYTE G1 Gaming Z170X Gaming 7 ~~~ G. Skill Ripjaws V 2x8GB DDR4-2800 ~~~ EVGA ACX 3.0 GTX 1080 SC @ 2GHz ~~~ EVGA P2 850W 80+ Platinum ~~~ Samsung 850 EVO 500GB ~~~ Crucial MX200 250GB ~~~ Crucial M500 240GB ~~~ Phanteks Enthoo Luxe

Link to comment
Share on other sites

Link to post
Share on other sites

53 minutes ago, Noirgheos said:

Recently completed a project for school, and used compare and various jump commands to get it done. While it worked without issue, my instructor said using loop commands would shorten it a decent bit. Thing is, loop commands have what... three conditions? Not to mention the loop distance limit. How could it shorten code?

while loops only have 1 condition 

while True:
	//code

will loop until the condition is met. Why don't you post your code and maybe we can post a shorter solution using loops.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, vorticalbox said:

while loops only have 1 condition 


while True:
	//code

will loop until the condition is met. Why don't you post your code and maybe we can post a shorter solution using loops.

.386                                    
.model flat, stdcall                   
option casemap :none                   

include \masm32\include\windows.inc         
include \masm32\include\kernel32.inc         
include \masm32\include\masm32.inc          
include \masm32\include\user32.inc          
include \masm32\include\debug.inc           
                                           
includelib \masm32\lib\kernel32.lib         
includelib \masm32\lib\user32.lib           
includelib \masm32\lib\masm32.lib           
includelib \masm32\lib\debug.lib            

.data

value dd 13							; Setting input value to whatever you like.

.code
start:

mov edx, 0							; Preparing EDX for division remainders.
mov eax, value						;
mov ebx, 2							;
mov ecx, 3							; Moving the rest of the values. 

evennum:							; Even number loop.
mov value, eax						; Moving value to EAX again.	
div ebx								; Dividing to get results.
cmp edx, 0
jne oddnum
PrintDec eax
jmp evennum

oddnum:
mov eax, value
cmp eax, 1
je endit
mul ecx
add eax, 1
PrintDec eax
jmp evennum

endit:
ret
end start

i7 6700K @ Stock (Yes I know) ~~~ Corsair H80i GT ~~~ GIGABYTE G1 Gaming Z170X Gaming 7 ~~~ G. Skill Ripjaws V 2x8GB DDR4-2800 ~~~ EVGA ACX 3.0 GTX 1080 SC @ 2GHz ~~~ EVGA P2 850W 80+ Platinum ~~~ Samsung 850 EVO 500GB ~~~ Crucial MX200 250GB ~~~ Crucial M500 240GB ~~~ Phanteks Enthoo Luxe

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, vorticalbox said:

while loops only have 1 condition 


while True:
	//code

will loop until the condition is met. Why don't you post your code and maybe we can post a shorter solution using loops.

Sorry for the half assed comments, but the code does indeed work. Just needed to replicate some operations.

i7 6700K @ Stock (Yes I know) ~~~ Corsair H80i GT ~~~ GIGABYTE G1 Gaming Z170X Gaming 7 ~~~ G. Skill Ripjaws V 2x8GB DDR4-2800 ~~~ EVGA ACX 3.0 GTX 1080 SC @ 2GHz ~~~ EVGA P2 850W 80+ Platinum ~~~ Samsung 850 EVO 500GB ~~~ Crucial MX200 250GB ~~~ Crucial M500 240GB ~~~ Phanteks Enthoo Luxe

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Noirgheos said:

Recently completed a project for school, and used compare and various jump commands to get it done. While it worked without issue, my instructor said using loop commands would shorten it a decent bit. Thing is, loop commands have what... three conditions? Not to mention the loop distance limit. How could it shorten code?

The x86 LOOP assembly instructions will decrease ECX and jump to the given address if ECX becomes equal to 0 automatically. That's both faster in execution time and shorter to code then performing a manual test for loops that require n iterations.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×