; ======================== source-file: _rl_sum.asm ==========================
;
; PURPOSE:
; Calculates and returns the sum of all elements in a real number List.
;
;GLOBAL DOMAINS
; RLIST = REAL*
;
;GLOBAL PREDICATES
; REAL rl_sum(RLIST) -(i) language c
IDEAL
P586
P587
MODEL flat
CODESEG
align 4
public _rl_sum
PROC _rl_sum
push ebp
mov ebp,esp
add esp,-8
mov eax,[dword ptr ebp+8] ;
xor edx,edx ;
mov [dword ptr ebp-8],edx ;
mov [dword ptr ebp-4],edx ;
mov edx,12 ;
push ebx ;
mov ebx,4 ;
mov ch,1 ;
jmp short @@p2 ;
; ===========================
@@p1:
fld [qword ptr eax+ebx] ;
fadd [qword ptr ebp-8] ;
fstp [qword ptr ebp-8] ;
mov eax,[dword ptr eax+edx] ;
@@p2:
mov cl,[byte ptr eax] ;
cmp cl,ch ;
je short @@p1 ;
; -------------------------------
pop ebx ;
fld [qword ptr ebp-8] ;
pop ecx ;
pop ecx ;
pop ebp ;
ret
ENDP _rl_sum
END
/****************** Visual Prolog TESTING PROGRAM (as an EasyWin project): ***************/
GLOBAL DOMAINS
RLIST = REAL*
GLOBAL PREDICATES
REAL rl_sum(RLIST) -(i) language c
GOAL
repeat, write("\nGive a list of real numbers:\n> "), readln(S),
term_str(rlist,Lx,S), Nx = rl_sum(Lx),
write("Sum = ",Nx), nl, readchar(Cx), Cx='\27', !.
; ************** "32-bit Assembly Language Extensions for Visual Prolog" ****************
; Written by George A. Stathis (c) 2005, E-mail: omadeon@yahoo.com, gstathis@enm.gr
; URL: http://www.omadeon.com/asm Company: ENB Ltd. Company site: http://www.enb.gr
; **** Use of this source-code is unrestricted provided that the author is mentioned. ****