
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


Get two integers from the user.

Then,   display a message if the first integer is:

   less than, 
   equal to,   or 
   greater than
the second integer.



Test the condition   for each case separately,   so that   all three comparison operators are used   in the code.



Related task

   String comparison


.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
 
.text
.global _start
 
_start:
	stp x29, x30, [sp, -16]!
	mov x0, #123
	mov x1, #456
	mov x29, sp
	bl integer_compare // integer_compare(123, 456);
	mov x0, #-123
	mov x1, #-456
	bl integer_compare // integer_compare(-123, -456);
	mov x0, #123
	mov x1, #123
	bl integer_compare // integer_compare(123, 123);
	ldp x29, x30, [sp], 16
	mov x0, #0
	b _exit // exit(0);
 
// void integer_compare(long long x, long long y) - compare two signed integers and print a message
integer_compare:
	cmp x0, x1
	mov x0, #STDOUT
	b.eq 1f
	b.gt 2f
	// x < y
	ldr x1, =msg_lt
	mov x2, #17
	b _write
1:	// x == y
	ldr x1, =msg_eq
	mov x2, #16
	b _write
2:	// x > y
	ldr x1, =msg_gt
	mov x2, #20
	b _write
 
msg_lt:
	.ascii "x is less than y\n"
msg_eq:
	.ascii "x is equal to y\n"
msg_gt:
	.ascii "x is greater than y\n"
.align 4
 
//////////////// system call wrappers
// ssize_t _write(int fd, void *buf, size_t count)
_write:
	stp x29, x30, [sp, -16]!
	mov x8, #SVC_WRITE
	mov x29, sp
	svc #0
	ldp x29, x30, [sp], 16
	ret
 
// void _exit(int retval)
_exit:
	mov x8, #SVC_EXIT
	svc #0