The var1 byte is declared as follows:
var1 db 1

Why doesn't this work:

mov ah, var1
cmp ah, 1
jmp is1 ; Doesn't jump to is1

While this works:

mov ax, var1
cmp ah, 1
jmp is1 ; Does jump to is1


Any help would be appreciated.
Posted on 2002-07-15 18:39:22 by gregd
Well first you should have je instead of jmp. Or is that just a typo

Otherwise the first looks like it should work.
Posted on 2002-07-15 18:47:38 by Eóin
Yes, sorry, it was a typo. I actually have jz there. (not je)

mov ah, var1
cmp ah, 1
jz is1 ; Doesn't jump to is1

So I assume, when ah gets compared to var, zf is set to 0, because i compare to 1, and ah should be one too (var1). jz then tells that if zf is zero then jump to is1. It doesn't jump there for some reason. However, this works:

mov ax, var1
cmp ah, 1
jz is1;

This one does the same, but it stores var in ax(and it puts it into ah presumably), so then i test if ah and 1 are equal, get 0 in zf, and jump to is1, if zf is 0. This one works. But I can't understand why the ah/ah doesn't work. I literally switch ax and ah, the code stays exactly the same.
Posted on 2002-07-15 20:45:02 by gregd
I can't expalin it, when I tried the following code the MessageBox didn't display, therefore it did jump

.data
var db 1

.code
mov ah,var
cmp ah,1
jz @F
invoke MessageBox,0,CT("Not Equal"),0,0
@@:

Perhaps if you post more of the code, the problem's most likely somewhere else.
Posted on 2002-07-16 07:22:58 by Eóin

So I assume, when ah gets compared to var, zf is set to 0, because i compare to 1, and ah should be one too (var1). jz then tells that if zf is zero then jump to is1. It doesn't jump there for some reason.


This isn't true, the zero flag is set if they are equal.
You must remember that the cmp instruction is a subtraction which doesn't store the result, but does modify the flags.
It is for this reason that you should use je (jump equal) rather than jz (jump zero) when doing comparisons. It avoids confusion.

However the other half of your statement is also wrong which nullifies the point! jz jumps if the zero flag is set.

The mere fact that moving a single byte, into a two byte register works is somewhat worrying though (MASM should throw a wobbly when it tries to assemble that instruction). I suspect at this point, you've probably forgotten something about your code, and this may be the reason everything is going wrong.

Mirno
Posted on 2002-07-16 08:50:23 by Mirno
I just figured out when i do something like this:

mov ah,
cmp ah, 1
jmp is1

it does work, so nothing is wrong with the rest of code. There's not much code in there after all, just a few lines.

But I still dont understand why

mov ah, var1

Doesnt have same results.
Posted on 2002-07-16 11:35:23 by gregd
Are you sure
mov ah, var1

cmp ah, 1
jz is1 ; Doesn't jump to is1
doesn't work???

There's a lot of error in program logic when it comes to the variations of jump instructions. Be careful when implementing one.
.686

.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE \masm32\include\windows.inc
INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib

.DATA

var1 DB 1
ahIs1 DB "AH is 1", 0
ahIsNot1 DB "AH is not 1", 0

.CODE

START:

mov ah, var1
cmp ah, 1
jz __ah_is_1

invoke MessageBox, 0, OFFSET ahIsNot1, 0, 0
jmp __exit

__ah_is_1:

invoke MessageBox, 0, OFFSET ahIs1, 0, 0

__exit:

invoke ExitProcess, 0

END START
Hey it worked...

jmp is an unconditional jump, it doesn't care the state of the flags, it justs jumps.
Posted on 2002-07-16 11:43:57 by stryker
It must be because he's using NASM under DOS?

If var1 is located at 01xxh, it would explain the behavior because NASM uses [] differently from MASM.
Posted on 2002-07-16 14:50:31 by tenkey