added default case (a > b) to have fewer operations
section .text global max ; declare max function max: ; int max(int a, int b) mov rax, rdi ; let the default case be a > b cmp rax, rsi ; compare a ?= b jge _end ; jump to end if a >= b mov rax, rsi ; assigne rax to b if a < b _end: ret
- section .text
- global max ; declare max function
max: ; int max(int a, int b)cmp rdi, rsi ; compare a ?= bjle _lower ; jump to lower if a <= bjmp _greater ; jump to greater if a > b_lower:mov rax, rsi ; assgine rax to bjmp _end ; end program_greater:mov rax, rdi ; assgine rax to a- max: ; int max(int a, int b)
- mov rax, rdi ; let the default case be a > b
- cmp rax, rsi ; compare a ?= b
- jge _end ; jump to end if a >= b
- mov rax, rsi ; assigne rax to b if a < b
- _end:
- ret