News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

add+mul

Started by imadhx30, February 01, 2014, 11:19:40 AM

Previous topic - Next topic

imadhx30

how does the program masm32!!
a^0*b^n+...........................+a^n*b^0

Farabi

You'll have to know the order of the multiplication and the addition and doing it one by one. There is a function on the FPU for the exponential and addition to solve your problem. But I forget how to use the exponent function using FPU.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

imadhx30

my program not calculate the formula gives!!
just calculated the power a^n


.386
.model flat,stdcall
option casemap:none
include\masm32\include\masm32.inc
include\masm32\include\kernel32.inc
include\masm32\include\msvcrt.inc
includelib\masm32\lib\masm32.lib
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\msvcrt.lib
;---------------------------------------------------------
somiter proto :DWORD,:DWORD
.data
ms1 db "donner a : ",0
ms4 db "donner b : ",0
ms3 db "donner  n : ",0
ms2 db "la somme final est : %d ",0
format db "%d",0
.data?
a dd ?
b dd ?
n dd ?
tab dd 25 dup(?)
.code
start:
push offset ms1
call crt_printf
push offset a
push offset format
call crt_scanf
push offset ms4
call crt_printf
push offset b
push offset format
call crt_scanf
push offset ms3
call crt_printf
push offset n
push offset format
call crt_scanf
invoke somiter,a,n
push eax
push offset ms2
call crt_printf
ici:jmp ici
invoke ExitProcess,0
;---------------------------------------------
somiter proc x:DWORD,z:DWORD
mov eax,x
mov edx,z
    cmp edx,0
    je els
repete:
    dec z
    jz fin
    mov ebx,x
    mul ebx
jmp repete   
    els:
    mov eax,1
    fin:
    ret
    somiter endp
    end start



hutch--

Something you need to do with your called procedure, preserve EBX. It must be the same on exit as it was on entry or you can get problems with both API functions and MSVCRT functions.


somiter proc x:DWORD,z:DWORD

    push ebx  ; preserve here

mov eax,x
mov edx,z
    cmp edx,0
    je els
repete:
    dec z
    jz fin
    mov ebx,x
    mul ebx
jmp repete   
    els:
    mov eax,1
    fin:

    pop ebx    ; restore here

    ret
    somiter endp

    end start


In this case you could have used ECX instead of EBX but its worth knowing about preserving and restoring registers.

dedndave

i guess a and n are integers ?
if so, i have a ling long kai fang routine for that

http://masm32.com/board/index.php?topic=222.0

imadhx30

my program not calculate the formula a^0*b^n+a^1*b^n-1+...........................+a^n*b^0
help,:me

qWord

Quote from: imadhx30 on February 01, 2014, 12:42:46 PM
my program not calculate the formula a^0*b^n+a^1*b^n-1+...........................+a^n*b^0
a0bn+a1bn-1+...+anb0 == bn+a(bn-1+a(bn-2+a(...+a(b+a))))
include \masm32\include\masm32rt.inc
.code
main proc
LOCAL a:REAL8,b:REAL8,n:DWORD,x:REAL8

    finit
    print "double a = "
    fncx crt_scanf,"%lG",&a
    print "double b = "
    fncx crt_scanf,"%lG",&b
    print "unsigned int n = "
    fncx crt_scanf,"%u",&n
   
    fld1
    fld1
    mov ecx,n
    jmp @w
@@:
    fmul a
    fld b
    fmulp st(2),st
    fadd st,st(1)
@w: add ecx,-1
    jge @B
    fstp st(1)
    fstp x
    fncx crt_printf,"%.6G\n",x
   
    inkey
    exit   
main endp
end main
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

Hi qWord,

Quote from: qWord on February 01, 2014, 03:24:49 PM
a0bn+a1bn-1+...+anb0 == bn+a(bn-1+a(bn-2+a(...+a(b+a))))

well done.  :t It's the well known Horner's method.

Gunther
You have to know the facts before you can distort them.

imadhx30


qWord  :t

give another example except following library:
include \ masm32 \ include \ kernel32.inc
include \ masm32 \ include \ masm32.inc
include \ masm32 \ include \ msvcrt.inc
includelib \ masm32 \ lib \ masm32.lib
includelib \ masm32 \ lib \ kernel32.lib
includelib \ masm32 \ lib \ msvcrt.lib

dedndave

i think there's a way to solve the geometric series without iteration
i just don't remember what it is   :lol:

imad...
INC files are plain text files - you can examine them with NotePad
have a look at the file \masm32\include\masm32rt.inc   :t

imadhx30

but not included /masm32rt.inc   :icon_exclaim:
plz corrigé my programme
   :(
.386
.model flat,stdcall
option casemap:none
include\masm32\include\masm32.inc
include\masm32\include\kernel32.inc
include\masm32\include\msvcrt.inc
includelib\masm32\lib\masm32.lib
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\msvcrt.lib
;---------------------------------------------------------
somiter proto :DWORD,:DWORD
.data
ms1 db "donner a : ",0
ms4 db "donner b : ",0
ms3 db "donner  n : ",0
ms2 db "la somme est : %d ",0
format db "%d",0
.data?
a dd ?
b dd ?
n dd ?
tab dd 25 dup(?)
.code
start:
push offset ms1
call crt_printf
push offset a
push offset format
call crt_scanf
push offset ms4
call crt_printf
push offset b
push offset format
call crt_scanf
push offset ms3
call crt_printf
push offset n
push offset format
call crt_scanf
invoke somiter,a,n
push eax
push offset ms2
call crt_printf
ici:jmp ici
invoke ExitProcess,0
;---------------------------------------------
somiter proc x:DWORD,z:DWORD
mov eax,x
mov edx,z
    cmp edx,0
    je els
repete:
    dec z
    jz fin
    mov ebx,x
    mul ebx
jmp repete   
    els:
    mov eax,1
    fin:
    ret
    somiter endp
    end start



dedndave

start with something like this
.386 processor does not allow certain addressing modes - should be .486 minimum
also, windows.inc should be the first one included
and the masm32 library depends on msvcrt (probably a few others, too - like user32)
        .586
        .model  flat,stdcall
        option  casemap:none
        include     \masm32\include\windows.inc
        include     \masm32\include\kernel32.inc
        include     \masm32\include\msvcrt.inc
        include     \masm32\include\masm32.inc
        includelib  \masm32\lib\kernel32.lib
        includelib  \masm32\lib\msvcrt.lib
        includelib  \masm32\lib\masm32.lib

imadhx30

give a solution used except (a^0*b^n+...........................+a^n*b^0)
use except:
include\masm32\include\masm32.inc
include\masm32\include\kernel32.inc
include\masm32\include\msvcrt.inc
includelib\masm32\lib\masm32.lib
includelib\masm32\lib\kernel32.lib
includelib\masm32\lib\msvcrt.lib
:icon_redface: :icon_redface: :icon_redface: :icon_redface:

qWord

learn programming or drop out of college.
MREAL macros - when you need floating point arithmetic while assembling!

TWell

Quote from: qWord on February 02, 2014, 04:51:28 AM
learn programming or drop out of college.
If you don't want to use masm32rt.inc think about another forum.