Added a simple program for compare numbers

This commit is contained in:
Fabio Scotto di Santolo
2025-07-02 16:04:05 +02:00
parent d65227d1f3
commit 7b989eb032
2 changed files with 46 additions and 0 deletions

46
max.asm Normal file
View File

@@ -0,0 +1,46 @@
; A simple program that print in output
; the max between two numbers.
;
; Author: Fabio Scotto di Santolo
; Date: 02/07/2025
global _start
section .text
_start:
mov eax, [a] ; load a value in eax register
mov ebx, [b] ; load b value in ebx register
cmp eax, ebx ; compare a and b values
jg greater
jle less_or_equal
less_or_equal: ; print b is greater or equal than b
mov eax, 0x04 ; write syscall
mov ebx, 1 ; STDOUT file descriptor
mov ecx, msg1
mov edx, len1
int 0x80 ; trigger syscall
jmp end
greater: ; print a is greater than b
mov eax, 0x04 ; write syscall
mov ebx, 1 ; STDOUT file descriptor
mov ecx, msg2
mov edx, len2
int 0x80 ; trigger syscall
jmp end
end:
; call syscall exit
mov eax, 0x1
xor ebx, ebx ; reset register to 0
int 0x80 ; trigger syscall
section .data
a: dd 10
b: dd 40
msg1: db "A is less or equal than B", 0xA
len1: equ $ - msg1
msg2: db "A is greater than B", 0xA
len2: equ $ - msg2