.286				;enable 286 commands at least
e equ db 66h                    ;operand size prefix (32 bit commands)
w equ word ptr

code segment public
assume cs:code
public root
public rootfct
                                ;radicand value in dx:ax
root proc pascal                ;result in ax (function)
e				;computer with 32 bits
	xor si,si		;clear intermediate result (in esi)
  db 66h,0fh,0ach,0d3h,10h	;shrd ebx,edx,16d - dx to ebx (upper 16 bits)
	mov bx,ax		;ax to ebx (down) - dx:ax now in ebx
e
  xor dx,dx			;clear edx
e
	mov cx,bx		;store initial value in ecx
e
  mov ax,bx			;load eax also

iterat:
e
  idiv bx                       ;divide by Xn
e
	xor dx,dx		;remainder unimportant
e
	add ax,bx		;add Xn
e
	shr ax,1		;divide by 2
e
	sub si,ax               ;difference to previous result
e
	cmp si,1                ;less than equal to 1
  jbe finished                  ;then finished
e
	mov si,ax               ;store result as previous
e
  mov bx,ax                     ;record as Xn
e
	mov ax,cx               ;reload initial value for division
  jmp iterat                    ;and go to beginning of loop
finished:
  ret                           ;result now in eax
root endp

rootfct proc pascal a:dword	;translates procedure to Pascal function
	mov ax,word ptr a       ;write parameters to register
  mov dx,word ptr a+2
  call root                     ;and extract root
	ret
rootfct endp
code ends
end
