The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: multi_coder on March 02, 2011, 03:06:16 AM

Title: Multiply function
Post by: multi_coder on March 02, 2011, 03:06:16 AM
Hello all. I am familiar to many other programming languages and am trying to learn assembly. I know it may be a bit redundant to make a function to multiply a number but I wanted to write something simple for my first function in assembly. I am unable to make the function invoke. I know I have to be making a silly mistake but I just don't see it.


.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

.data
        HelloWorld  db "HelloWorld!", 0
        Answer      db "The answer is...", 0
        Sout   db "NotNull", 0
.code
;;;;FMul proto :DWORD, :DWORD
start:
        xor ecx, ecx
        xor eax, eax
        add eax, 2
        ;inc eax, 1
        add ecx, 7
        ; Build a !7 loop
        xor eax, eax
        ;invoke FMul
        invoke FMul, 5, 5
;_label: add eax, ecx
;        ;mov edx, eax
;        ;mul edx, 1
;        dec ecx
;        jnz _label
       
        invoke dwtoa,eax,addr Sout
        invoke MessageBox, NULL, addr Sout, addr Answer, MB_OK
        invoke ExitProcess, 0

end start

FMul proc value:DWORD, times:DWORD
        ;xor ecx,ecx
        ;xor eax,eax
_LMul:  add eax, value
        dec eax
        jnz _LMul
    ret
endp

Title: Re: Multiply function
Post by: clive on March 02, 2011, 03:40:40 AM
You should pick names that aren't keywords or opcodes.

.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib

.data
        HelloWorld  db "HelloWorld!", 0
        Answer      db "The answer is...", 0
        Sout   db "NotNull", 0
.code
        _FMul proto :DWORD, :DWORD
start:
        invoke _FMul, 5, 5
        invoke dwtoa,eax,addr Sout
        invoke MessageBox, NULL, addr Sout, addr Answer, MB_OK
        invoke ExitProcess, 0

_FMul   proc value:DWORD, times:DWORD
        mov ecx,times
        xor eax,eax
_LMul:  add eax, value
        dec ecx
        jnz _LMul
        ret
_FMul   endp

        end     start
Title: Re: Multiply function
Post by: multi_coder on March 03, 2011, 09:22:02 PM
Thanks you for the assistance. I will keep away from op code function names in the future for clarity.