flat assembler
Message board for the users of flat assembler.

Index > Windows > Simple application i cant workout

Author
Thread Post new topic Reply to topic
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
Hi every one, i was reading up on jump statments and wanted to make a simple program which compares 2 variables and shows a messageBox depending on which value. The code is below.

Code:
include 'C:\fasmw164\INCLUDE\win32ax.inc'

msgBoxCaption  db   '???',0
msgBoxText     db   'Not Equal too',0
msgBoxText1    db   'Equal too',0


mov ax, 10
mov bx, 10
cmp ax,bx
jne start
jmp start1

start:
          push MB_OK
          push msgBoxCaption
          push msgBoxText
          push NULL
          call [MessageBox]
          jmp exitP
.end start ; Here is the problem





     start1:

          push MB_OK
          push msgBoxCaption
          push msgBoxText1
          push NULL
          call [MessageBox]
          jmp exitP
          
exitP:
invoke ExitProcess,0
    


The problem is that if i remove ".end start" the program will not assemble. But i leave it the way it is (with it in the code) then jne goes directly to "start:" even though the two values are equal (ax, bx both equal 10).
Could any one help me out with this problem? I'd really appreciate it.

P.S
Sorry if im speaking kinda weird crap cause im only beginning and i don't really know that much about ASM.

Thanks in advance, Jack.
Post 19 Nov 2005, 10:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Take in mind that the execution of the program begins at "start:" or the label you put in ".end" which is "start" in this case.

This will work:
Code:
include 'C:\fasmw164\INCLUDE\win32ax.inc' 

msgBoxCaption  db   '???',0 
msgBoxText     db   'Not Equal too',0 
msgBoxText1    db   'Equal too',0 

start:
mov ax, 10 
mov bx, 10 
cmp ax,bx 
jne start2
jmp start1 

start2: 
          push MB_OK 
          push msgBoxCaption 
          push msgBoxText 
          push NULL 
          call [MessageBox] 
          jmp exitP 


     start1: 

          push MB_OK 
          push msgBoxCaption 
          push msgBoxText1 
          push NULL 
          call [MessageBox] 
          jmp exitP 
           
exitP: 
invoke ExitProcess,0

.end start ; Put this always at the end of the code. Check .end macro in win32ax.inc to see why    
Post 19 Nov 2005, 13:44
View user's profile Send private message Reply with quote
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
thank you very much locodelassembly, i will look up on macro and find out more about it. Hopefully it will help me when i make w32 applications.

Thanks again Jack.
Post 20 Nov 2005, 04:27
View user's profile Send private message Reply with quote
jdawg



Joined: 26 Jun 2005
Posts: 39
jdawg
Here are two macros I use for min and max that could help. Though I'm sure if you asked one of the senoir members you could get more effecient ones.
Code:
macro min a,b
{
    mov    eax,a
    mov    ecx,b
    cmp    eax,ecx
    jg       RetB       ;return b (in eax) if eax<ecx
    jmp    finish
  RetB:
   mov    eax,b
  finish:
}

macro max a,b
{
   mov    eax,a
   mov    ecx,b
   cmp    eax,ecx
   jl        RetB      ;return b (in eax) if eax>ecx
   jmp    finish
 RetB:
   mov   eax,b
 finish:
}
    


They look the same, but notice the subtle "jg" and "jl". That's all it takes. The pros probably know a better way though.
Post 03 Dec 2005, 21:06
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
If your processor supports cmovXX instructions (most do now)
;;Unsigned min
mov eax, a
mov ecx, b
cmp eax,ecx
cmova eax,ecx
;;Unsigned max
mov eax, a
mov ecx, b
cmp eax,ecx
cmovb eax,ecx

;;Signed min
mov eax, a
mov ecx, b
cmp eax,ecx
cmovg eax,ecx
;;Signed max
mov eax, a
mov ecx, b
cmp eax,ecx
cmovl eax,ecx

I used to like the novell SBB AND ADD method but after benchmarking using CMOV is fastest.
Post 04 Dec 2005, 06:29
View user's profile Send private message AIM Address Yahoo Messenger 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.