News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

jump to label?

Started by j00n, October 27, 2011, 09:54:04 PM

Previous topic - Next topic

j00n

include \masm32\include\masm32rt.inc

.data

   num1 sdword 5
   
.data?

.const

.code

start:

    main proc

    mov eax, 3             
    cmp num1, eax               ;5 - 3    compare 5 and 3
    je eqqq                     ;jump over(not equal) to eqqq
    print "not equal", 0Ah      ;else print not equal
eqqq: print "equal", 0Ah
    inkey                       ;wait for input

    ret
 
    main endp

end start



I can't get around this problem i'm having where both labels are printed when I only need one or the other...

is there a way to make a label only appear when called?

like this

error1: print "error1"
error2: print "error2"

these only show when I jump to them?


**Updated solution code**

include \masm32\include\masm32rt.inc

.data

   num1 sdword 5
   
.data?

.const

.code

start:

    main proc
   
    mov eax, 3             
    cmp num1, eax               ;5 - 3    compare 5 and 3
    je eqqq                     ;jump if equal to label eqqq
    jne neqq                    ;jump if not equal to label neqq

eqqq: print "equal", 0Ah
jmp @fin
neqq: print "not equal", 0Ah
jmp @fin

    @fin:

    inkey "Press any key to exit"

    ret
    main endp
   
end start

qWord

Quote from: j00n on October 27, 2011, 09:54:04 PMlike this

error1: print "error1"
error2: print "error2"

these only show when I jump to them?
No.
You must declare a second label:
error1: print "error1"
jmp @fin
error2: print "error2"
jmp @fin
[....]
@fin:

Also you can use MASM .if/.elseif/.else/.endif Constructs or MASM32's switch-macros.
FPU in a trice: SmplMath
It's that simple!

dedndave

   je eqqq                     ;jump over(not equal) to eqqq

   print ("not equal"),0Dh,0Ah ;else print not equal
   jmp  done

eqqq: print ("equal"),0Dh,0Ah

done:
   inkey                       ;wait for input


in this case, you could "share" part of the string....
   je eqqq                     ;jump over(not equal) to eqqq

   print ("not ")              ;else print not equal

eqqq: print ("equal"),0Dh,0Ah
   inkey                       ;wait for input


is that what you mean ?

j00n

Thanks for your help, I updated my post with the final code.

dedndave

eqqq: print "equal", 0Ah
jmp @fin
neqq: print "not equal", 0Ah
jmp @fin                                ;you may omit this JMP

    @fin: