Lesson 9 of 15

Conditional Jumps

Conditional Jumps

Conditional jumps change the flow of execution based on flags. You typically set flags with cmp or test, then jump.

Signed vs Unsigned Comparisons

For signed comparisons (treating values as positive or negative):

  • jg / jge / jl / jle

For unsigned comparisons (treating values as always positive):

  • ja / jae / jb / jbe

If-Else Pattern

	cmp rax, 10
	jl less_than       ; if rax < 10, jump
	; else branch here
	jmp end
less_than:
	; if branch here
end:

Chained If-Else (if/elif/else)

	cmp rax, 0
	jl negative
	je zero
	; positive branch
	jmp end
negative:
	; negative branch
	jmp end
zero:
	; zero branch
end:

Your Task

Write a program that classifies a number:

  • If the number (stored in rax) is greater than 0, print "P\n" (positive)
  • If the number is 0, print "Z\n" (zero)
  • If the number is less than 0, print "N\n" (negative)

Test with the value 42 -- it should print "P\n". Then test with 0 -- it should print "Z\n". Then test with -5 -- it should print "N\n".

Print all three results: "P\nZ\nN\n"

x86_64 runtime loading...
Loading...
Click "Run" to execute your code.