Created
February 3, 2024 12:10
-
-
Save dan0nchik/42a84f03011fe19f084b653573d8d076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addi x17, x0, 5 # read a (a is put in x10) | |
ecall | |
add x6, x0, x10 # store "a" in x6 | |
srli x5, x10, 31 # store sign of "a" in x5 | |
ecall | |
add x29, x0, x10 # store "b" in x29 | |
srli x28, x10, 31 # store sign of "b" in x28 | |
beq x6, x0, if_a_zero # branch if a is zero (???) | |
beq x29, x0, if_b_zero #branch if b is zero (???) | |
beq x5, x0, if_a_less_0 # branch if "a" < 0 then inverse it | |
if_a_less_0: | |
xori x6, x6, -1 | |
addi x6, x6, 1 | |
beq x28, x0, if_b_less_0 # branch if "b" < 0 then inverse it | |
if_b_less_0: | |
xori x29, x29, -1 | |
addi x29, x29, 1 | |
bge x6, x29, if_a_less_b # branch if "a" < "b" swap them | |
if_a_less_b: | |
xor x29, x29, x6 | |
xor x6, x29, x6 | |
xor x29, x29, x6 | |
add x7, x0, x0 | |
add x7, x7, x6 | |
addi x29, x29, -1 | |
blt x0, x29, if_b_more_0 # branch if b > 0 -> x31 = -b | |
if_b_more_0: | |
xor x31, x5, x28 | |
beq x31, x0, 12 # branch if x31 is zero (???) | |
xori x7, x7, -1 | |
addi x7, x7, 1 # t2 - result accumulator | |
addi x17, x0, 1 | |
add x10, x0, x7 | |
ecall | |
addi x17, x0, 10 | |
ecall | |
addi x17, x0, 1 # if sign of "a" and "b" is different then negate the result | |
add x10, x0, x0 | |
ecall | |
addi x17, x0, 10 | |
ecall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment