News:

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

MASM multiplication

Started by lgarcia3, February 13, 2006, 04:28:43 PM

Previous topic - Next topic

lgarcia3

My boss gave me a "simple" project to do. Problem is I don't know ASM. But... is the boss... I have to calculate the following in MASM:

n * 16^x

It has to be in a function which we pass n and x and get the result back. I have no idea how to do that. Can anyone help?
Thanks!

Tedd


funcy proc val_n:DWORD,val_x:DWORD

    ;eax = 1
    ;multiply eax by 16 - repeat this 'val_x' times (you will probably want to take care of the high-part being in edx after each mul)
    ;multiply eax by val_n

    ;(the result is in eax)
    ret
funcy endp


This is, of course, limited to whole numbers, and 2^32 range (unless you do something smart and implement long-multiplication)
You may want to use floating-point instead.
No snowflake in an avalanche feels responsible.

lgarcia3

Thanks for your reply. It did not work. It fires this error:

multi.asm(22) : error A2119: language type must be specified

Thanks again!

EduardoS

Why your boss want asm if you don't know asm?
BTW, To do n * 16^x:

funcy proc n:DWORD, x:DWORD
mov ecx, x
mov eax, n
shl ecx, 2
shl eax, cl
ret
funcy endp

lgarcia3

Because he is almighty BOSS! :lol
Nah, actually, he wants me to learn a little bit since we have other projects that may need this. He gave me something "simple" to do and a book to read. I read the book... and I still don't know how to do it!  :( That's why

arafel

Quote from: lgarcia3 on February 13, 2006, 07:45:13 PM
Thanks for your reply. It did not work. It fires this error:

multi.asm(22) : error A2119: language type must be specified

you should include ".486" (.586 or whatever suits you) in your source.

Quote from: EduardoS on February 13, 2006, 09:06:50 PM
Why your boss want asm if you don't know asm?

boss = teacher  ::)

lgarcia3

I'm getting the same darn error.  :'(

I am using ml from microsoft. Don't know if that makes a difference. Here:

Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: multi.asm
multi.asm(22) : error A2119: language type must be specified
multi.asm(30) : warning A4003: start address on END directive ignored with .STARTUP
multi.asm(23) : error A2006: undefined symbol : x
multi.asm(24) : error A2006: undefined symbol : n


Thanks guys!

lgarcia3

I included that and did not work. Here is the code:


TITLE   MULTIPLICATION_PRACTICE

.MODEL SMALL
.486
.STACK 100H
.DATA
decnum         DW     ?
exponent    DW     4
.CODE

;--------------------------------------------------------------
main    PROC
.STARTUP

.EXIT
main    ENDP

funcy proc n:DWORD, x:DWORD
mov ecx, x
mov eax, n
shl ecx, 2
shl eax, cl
ret
funcy endp

END   main

arafel

There is no need for .STARTUP as you already specified startup address after the end directive (last line)
Also language type identifier should follow .MODEL statement. (.model small, stdcall)
.EXIT is unnecessary too.

everything else is left as an exercise for you  :wink

Oh and I suppose you'll need a 16bit capable linker for all this.

sluggy

lgarcia3,
this sounds like homework. Bosses don't just give out simple little problems like that. Next time read the forum rules, and don't try to mislead us. And make sure you give credit where credit is due, tell your teacher that you got assistance from several members of the MASM forum.

lgarcia3

With all due respect mr./mrs. moderator. I am an engineer. I work for Shell Oil Company in Houston, TX. Have done so for 6 years now (after graduating cum laude from Texas A&M University with a MS in Mechanical Engineering). We do all kind of reasearch, development and software implementations here. I have had to learn other uncommon languages in the past (LISP, fortran which I saw once in school and never again until last year, and now this). Bosses DO give things to learn and this is NO homework. Well, in a way it is since I have to learn it. But I am NOT misleading you. There is a TON of forums on the internet and the reason why I chose this is because it does looks good.

Anyway, that said, I still have problems with this. It worked patially. But still get errors for the language thing. I am getting this now:

Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: multi.asm
multi.asm(3) : error A2065: expected : memory model
multi.asm(3) : error A2013: .MODEL must precede this directive
multi.asm(5) : error A2013: .MODEL must precede this directive
multi.asm(6) : error A2013: .MODEL must precede this directive
multi.asm(7) : error A2034: must be in segment block
multi.asm(8) : error A2034: must be in segment block
multi.asm(9) : error A2034: must be in segment block
multi.asm(10) : error A2034: must be in segment block
multi.asm(11) : error A2013: .MODEL must precede this directive
multi.asm(14) : error A2034: must be in segment block : main
multi.asm(22) : error A2034: must be in segment block
multi.asm(23) : fatal error A1010: unmatched block nesting : main

Any ideas?
Thanks!

raymond

lgarcia3

Don't expect to learn another programming language overnight. Since you already have learned some other language, you learning curve can be a lot faster than someone without such background. Before you can do anything usefull, you have to learn the basics and the syntax.

Note: Forget about 16-bit assembly; it has become a specialty which you may never use. Start immediately with 32-bit assembly.

If you are sincerely interested, I would suggest you start with the AoA (Art of Assembly) which you can download in HTML or PDF format from:
http://webster.cs.ucr.edu/AoA/Windows/index.html

Also download the MASM32 package. It has many, many examples you can learn from, a good text editor for your source files, and some tools for producing your final executables without the need for MAKE files.

Cheers from a Shell Canada retiree.

Raymond

     
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

lgarcia3

Raymond,
Thanks! I really appreciate the help. I found that yesterday night searching the internet. Yes, you're right. It was just one of those things done in a rush. I also found a nice IDE called RadASM. It looks good and it's free.
It is kind of confusing. Yesterday looking for information I found Assembly for Motorola, for Pentium, for... you name it!  :eek  And one may be quite different from the other. So I did not know what to read.
By the way, yesterday night I was able to figure out what the error was with the program and it compiled!  :U
Thanks again everyone.

hutch--

lgarcia3,

If you let us know about more about what you are doing, it would make things a lot easier. Posting errors from an unknown program for a likewise unknown OS platform leads to the impressin of some kid trying to get someone to do their homeword.

We need to know if its for 16 bit DOS or 32 bit Windows. Tell us enough to answer your question and there will probably be someone who can help you.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rags

just to be the devil's advocate, could this be the same person at:

codeguru
God made Man, but the monkey applied the glue -DEVO