News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Multiply function

Started by multi_coder, March 02, 2011, 03:06:16 AM

Previous topic - Next topic

multi_coder

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


clive

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
It could be a random act of randomness. Those happen a lot as well.

multi_coder

Thanks you for the assistance. I will keep away from op code function names in the future for clarity.