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

 

