Arm/abs

From ASMBits

arm/oddPrevious

Write a function that returns the absolute value of its parameter. The parameter is a two's-complement signed integer.

int abs (int n);

Expected solution length: Around 3 lines.

Sample Input

10
-10

Sample Output

10
10

ARM does have a negation instruction, but it is oddly named: reverse subtract from #0. There is also a less oddly-named alias called neg.

Write your solution here

x
 
1
.global _start
2
_start:
3
    mov r0, #10
4
    bl abs
5
    1: b 1b    // Done
6
7
.global abs
8
abs:
9
    
10
    
Upload a source file...