; uppermed.asm
section .data
section .text
global uppermed
uppermed:
push r15
mov rax, rsi
mov rdx, 0
mov r15, 2
div r15    ; unsigned rax=length/2, remainder in rdx
cmp rdx, 0    ; length = even or odd ?
je evenLength ; remainder = 0 = even length
mov r15d, dword[rdi+rax*4]  ; get arr[length/2]
mov dword[rcx], r15d        ; return median
evenLength:
mov r15d, dword[rdi+rax*4]  ; get arr[length/2]
mov dword[rcx], r15d        ; return upper median
pop r15
ret

 

