04-if.asm 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ;;; Required packages: nasm, gcc, gcc-multilib
  2. ;;; Compile commands:
  3. ;;; nasm -f elf 04-if.asm -o bin/04-if.o
  4. ;;; gcc -m32 -o bin/04-if bin/04-if.o
  5. ;;;
  6. section .data
  7. x dd 1000
  8. y dd 2000
  9. fmt_x_greater_then_y db "x is greater then y", 0xa, 0
  10. fmt_y_greater_then_x db "y is greater then x", 0xa, 0
  11. fmt_x_equals_y db "x and y are equal", 0xa, 0
  12. section .text
  13. extern printf
  14. global main
  15. main:
  16. ; jg - jump if greater
  17. ; jl - jump if less
  18. ; jge - jump if greater or equals
  19. ; jle - jump if less or equals
  20. ; je - jump if equals
  21. ; jne - jump if not equals
  22. ; jmp - jump in any case
  23. mov eax, DWORD [x]
  24. mov ebx, DWORD [y]
  25. cmp eax, ebx
  26. jg .xGreaterThenY ; jump to the label in case if eax > ebx
  27. mov eax, DWORD [x]
  28. mov ebx, DWORD [y]
  29. cmp eax, ebx
  30. jl .yGreaterThenX ; jump to the label in case if eax < ebx
  31. jmp .xEqualsY
  32. .xGreaterThenY: ; '.' character before label name created local label main.xGreaterThenY
  33. push fmt_x_greater_then_y
  34. call printf
  35. add esp, 4
  36. jmp .done
  37. .yGreaterThenX:
  38. push fmt_y_greater_then_x
  39. call printf
  40. add esp, 4
  41. jmp .done
  42. .xEqualsY:
  43. push fmt_x_equals_y
  44. call printf
  45. add esp, 4
  46. jmp .done
  47. .done:
  48. ; exit code
  49. mov eax, 1 ; 1 - system call sys_exit
  50. mov ebx, 0 ; 0 - error code 0
  51. int 0x80 ; processor interruption to run syscall