pub mul_low: mov r3, 0 ; result mov r4, 31 ; loop counter mull_loop: asr r5, r2, 31 and r5, r5, r1 lsl r5, r5, r4 add r3, r3, r5 lsl r2, r2, 1 sub r4, r4, 1 cmp r4, 0 jge mull_loop mov r1, r3 jmp r13 ; Calculates the absolute value of the value provided in the r1 register ; Based on Stanford's BitHacks ; Clobbers r2 pub abs: ; SHOULD BE INLINED ; mask = v >> 31 asr r2, r1, 31 ; v + mask add r1, r1, r2 ; return (v + mask) ^ mask xor r1, r1, r2 jmp r13 ; Calculates the minimum value of the two values provided in the r1 and r2 registers ; Based on Stanford's BitHacks ; Clobbers flags pub min: ; SHOULD BE INLINED ; x < y cmp r1, r2 lsr flags, flags, 2 ; -(x < y) neg flags, flags ; x ^ y xor r1, r1, r2 ; (x ^ y) & -(x < y) and r1, r1, flags ; return y ^ ((x ^ y) & -(x < y)) xor r1, r2, r1 jmp r13 ; Calculates the maximum value of the two values provided in the r1 and r2 registers ; Based on Stanford's BitHacks ; Clobbers r2 and flags pub max: ; SHOULD BE INLINED ; x < y cmp r1, r2 lsr flags, flags, 2 ; -(x < y) neg flags, flags ; x ^ y xor r2, r1, r2 ; (x ^ y) & -(x < y) and r2, r2, flags ; return x ^ ((x ^ y) & -(x < y)) xor r1, r1, r2 jmp r13