954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

jl and jg?

ok i have this problem in mind i wanted to try but i cant figure out whats wrong with my code..the program lets you input a string of integers then press another input as target..The target is then cmp to the string..the output should place lesser values on the string based on the specifed target ex.
string: 12456
target: 2
output: 1

.model small
.stack
.data
.code
start:
push 0ah ; push linefeed indication of stack
start1:
mov ah,1
int 21h
push ax      ; data place at stack
cmp al,0dh   
je out1       ; will jump if equal to cmp al,0dh
jne start1 ; will jump if not equal to cmp al,0dh
out1:
mov ah,2
mov dl,0ah ;linefeed
int 21h

target:
pop bx
mov ah,1
int 21h
tests:
cmp al,bl
jl out2
out2:
pop bx
mov ah,2
mov dl,al
int 21h
cmp al,0ah
jne tests
je fin
fin:
mov ah,4ch
int 21h
end start

need help...im just wondering how come it wont workout the way i wanted it to workout..

jingo1126
Junior Poster in Training
57 posts since Aug 2009
Reputation Points: 10
Solved Threads: 1
 

JL or JB / JC ; Jump less-than or jump below
JG or JA ; Jump greater-than or jump above

The CMP instruction subtracts the dest-src from each other,
and updates the FLAGS which can be tested by conditional jumps.
For instance JB is equivalent to JC (Jump if CF Set).

Example:
cmp a, b
jg label ; Jump if A > B

cmp a, b
jl label ; Jump if A < B

NotNull
Posting Whiz in Training
211 posts since Oct 2008
Reputation Points: 39
Solved Threads: 21
 

Not to cloud the issue, but first you need to deterimine if you are working with signed versus unsigned data? You need to use a different compare based upon the type of data you're using!

Above & Below --> Unsigned
Less & Greater --> Signed

Unsigned:
JA, JNBE Jump if above (>)
JAE JNB (>=)
JBE, JNA (<=)
JB, JNAE (<_

Signed:
JG, JNLE (>)
JGE, JNL (>=)
JLE, JNG (<=)
JL, JNGE (<)

wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
 

Suprisingly I did not know that JA was for unsigned
and JG was for signed, etc...
Thanks for the post wildgoose!

NotNull
Posting Whiz in Training
211 posts since Oct 2008
Reputation Points: 39
Solved Threads: 21
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You