flat assembler
Message board for the users of flat assembler.

Index > DOS > simple logical if

Author
Thread Post new topic This topic is locked: you cannot edit posts or make replies.
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
Hi,
I'm trying to learn the basics of asm and logical structure.. just trying my skills but i got stuck on this! why doesn't this work?? I want to compare the two numbers and if they are equal then jump to then. and if they are not jump to else? also tried it with registers.. but it doesn't work Sad

Code:
format MZ
use16

push    cs
pop     ds

mov   [num1],0
mov   [num2],1

cmp   [num1],num2
jmp   is_then
jmp   is_else

is_then:
        mov ah,9
        mov dx,msg_then
        int 21h
        jmp endif
is_else:
        mov ah,9
        mov dx,msg_else
        int 21h
endif:

xor ax,ax
int 16h

num1 db ?
num2 db ?
msg_then db 'Then!',24h
msg_else db 'Else!',24h    
Post 06 Aug 2005, 20:37
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Hi Hicel,
well it is basically right, but jmp is an unconditional jump, you must use conditional jumps je jb jo ...
and you can not compare direcly 2 memory address's contents with cmp,
put one in register, then compare register with memory,
or in case strings use cmpsb (compare string byte)
uhm, and dont forget to exit in a way...
Code:
format MZ
use16

push    cs
pop     ds

mov   [num1],0
mov   [num2],1

mov al,[num1]
cmp al,[num2]
jb   is_then  ; if below
jae   is_else ; if above or equal

is_then:
        mov ah,9
        mov dx,msg_then
        int 21h
        jmp endif
is_else:
        mov ah,9
        mov dx,msg_else
        int 21h
endif:

xor ax,ax ; wait for keypress
int 16h   ; bios function

int 20h ; exit program

num1 db ?
num2 db ?
msg_then db 'Then!',24h
msg_else db 'Else!',24h
    
Post 06 Aug 2005, 21:54
View user's profile Send private message Visit poster's website Reply with quote
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
Many thanks Matrix I just learned from you that there are different jumps.. from step to step I'm getting more into it Wink For those having the same problem: (never understood the description but now Wink )
Code:

EB       cb  JMP rel8                Jump short, relative,

77       cb  JA rel8                 Jump short if above 
73       cb  JAE rel8                Jump short if above or equal 
76       cb  JBE rel8                Jump short if below or equal 
72       cb  JC rel8                 Jump short if carry 
E3       cb  JECXZ rel8              Jump short if ECX register is 0
74       cb  JE rel8                 Jump short if equal 
7F       cb  JG rel8                 Jump short if greater 
7D       cb  JGE rel8                Jump short if greater or equal 
7C       cb  JL rel8                 Jump short if less 
7E       cb  JLE rel8                Jump short if less or equal 
75       cb  JNE rel8                Jump short if not equal 
71       cb  JNO rel8                Jump short if not overflow 
79       cb  JNS rel8                Jump short if not sign 
70       cb  JO rel8                 Jump short if overflow 
7A       cb  JPE rel8                Jump short if parity even 
7B       cb  JPO rel8                Jump short if parity odd 
78       cb  JS rel8                 Jump short if sign 
    
Post 07 Aug 2005, 11:26
View user's profile Send private message Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Bitdog
There are conditional signed jumps & unsigned jumps.
Your CHAR or INT = BYTE & WORD are usually unsigned values
and require unsigned jumps such as JA JB JZ etc.
Well, it's something to look into anyway.

INT 20h ; is an exit for a .COM file & you have an MZ format .EXE so

MOV AX,4C00h
INT 21h

might be best as an exit code.
But I haven't checked it all out to be sure of anything above.
I hope this helps somehow.
Sincerely Bitdog
Post 07 Aug 2005, 21:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic This topic is locked: you cannot edit posts or make replies.

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 YouTube, Twitter.

Website powered by rwasa.