; Jade Yu Cheng
; ICS 312
; Assignment 7 Exercise 3
; April 24, 2009
; The program driver_ex3.c defines the main function. It takes one command-line
; argument, which is a floating point number strictly larger than .5. The
; program then calls a function called compute_ln that computes the natural
; logarithm function.
%include "asm_io.inc"
%define x dword [ebp + 8] ; define x to be the argument
%define item dword [ebp - 4] ; local var that stores (x-1)/x
%define counter dword [ebp - 8] ; local var used to swap integer
segment .text
global compute_ln
compute_ln:
push ebp ; setup
mov ebp, esp ; setup
push ebx ; setup reserve ebx
sub esp, 8 ; set up space for 2 local vars
fld1 ; st0 = 1
fsub x ; st0 = 1-x
fstp item ; item = 1-x
fldz ; st0 = 0
fsub item ; st0 = x-1
fdiv x ; st0 = (x-1)/x
fst item ; item = (x-1)/x
fld item ; st0 = st1 = (x-1)/x, old sum and ele
mov ebx, 0 ; loop counter
add_loop:
cmp ebx, 100000 ; loop 100000 times
jz add_loop_end
inc ebx ; increment the loop counter
fxch st1 ; first work on item to item_new
fmul item ; st0 = ((x-1)/x)^n
mov counter, ebx ; st0 = ((x-1)/x)^n*(n-1)
fimul counter
inc counter ; st0 = ((x-1)/x)^n*(n-1)/n
fidiv counter
fxch st1 ; then work on updating the summation
fadd st1 ; add the new item to the old summation
jmp add_loop
add_loop_end:
add esp, 8
pop ebx ; clean up
mov esp, ebp ; clean up
pop ebp ; clean up
ret ; clean up