News:

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

Exponential .. Help if possible

Started by gusto, October 08, 2005, 05:38:45 AM

Previous topic - Next topic

gusto

Quote from: OceanJeff32 on October 09, 2005, 04:38:33 AM
Kip Irvine is the writer of that book you are studying too, he has all the source code for the book online, if that helps!

He's a teacher out of Florida. If I find his website again, I'll update this message, but yeah, I want to read that book...can I have it when you are done?  :lol

Oh well,

Jeff C
:'(


lol help me get through the semester and ill mail u my book.. no charge  :P

mnemonic

Quote from: gusto on October 08, 2005, 10:24:57 PM
ps. mnemonic.. the mulbyAdd, is that a call, or an example of what i should name my procedure?.. sorry, once agian i am a noooob  :toothy

Oh, sorry gusto. I saw your question very late.
It is just a name for a procedure I made up myself so we can refer to it in following conversation.
So it is just an example for a name for a function you would have to implement yourself, not a "call" for a predefined procedure :wink

It is good practice to split stuff up in separate procedures especially in the aspect of reusability (write a proc and use it then in a different one).
You might find MASM very handy when it comes to procedures.
MASM has, as you might already know, some high level language elements. You may define prototypes for procedures with the keyword "PROTO" and call them later easily with the "INVOKE" statement. This will save you the trouble of pushing arguments for yourself in the right order.
Browse some tutorials or query the forums in here. Definitively watch out for it as it makes much things easier.
Also have a look at the file "MASM32.HLP" which comes like many other files bundled in the MASM32 package.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

OceanJeff32

Quote from: gusto on October 12, 2005, 12:02:34 AM
lol help me get through the semester and ill mail u my book.. no charge  :P

Do you have to pass the class?  :lol :lol :lol

I'll help any way that I can.

Later guy,

Jeff c
:eek
Any good programmer knows, every large and/or small job, is equally large, to the programmer!

gusto

Quote from: OceanJeff32 on October 12, 2005, 08:42:45 AM
Quote from: gusto on October 12, 2005, 12:02:34 AM
lol help me get through the semester and ill mail u my book.. no charge  :P

Do you have to pass the class?  :lol :lol :lol

I'll help any way that I can.

Later guy,

Jeff c
:eek

at least a C.... start by helpin me figure this problem out  :U

oh and thx mnemonic, i tried puttin those in as calls andkept gettin errors lol...

Eóin

gusto, The code you've written doesn't multiply by 9, but multiplies by 8 and adds 9. Thats why it works for the first number, cause 92 = 81 = 9*8 + 9, but 93 = 729 and your calculation; 81*8 + 9 instead gives 657.

gusto

how is it multiplying by 8, if that number is never even mentioned? i thought all i was doing was adding 9's in loops.. now im even more lost lol  ::)

mnemonic

Quote from: gusto on October 13, 2005, 03:41:48 AM
now im even more lost lol  ::)

You would do better if you were following my hints and split the stuff up into procedures.
That way you're able to test the parts individually and go to the next part if the following works.
Get it on: Write a procedure that does multiplication by using addition.
Post your code to have it verified, it won't be much work :wink
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

gusto

edit: using tabs, so the code doesnt split on the post, too long to add spaces to each line, but you get the point.. .

include \masm615\include\irvine16.inc


.data

y dword 9

.code
main proc
startup
mov eax,1
call writedec
call crlf
mov ecx,6


mov eax,y
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,9
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,117
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,1197
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,11349
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,104445
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,949221
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,8579853
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,77366133
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,696885021
call writedec
call crlf
add y,eax
mov eax,y
add y,eax
mov eax,y
add y,eax
add eax,eax
add eax,0
call writedec
call crlf

exit
main endp
end main


i got it to work except for 9^11, too large a number... the way my code works isnt exactly what i wanted, i am going to keep working on it, but atleast i will get some credit for this.... can anybody help me on how to avoid adding the integers and just using the eax register and my variable y...

mnemonic

Quote from: gusto on October 13, 2005, 07:40:59 PM
edit: using tabs, so the code doesnt split on the post, too long to add spaces to each line, but you get the point.. .

Uhm... how should anybody get the point if you didn't put any comments in here.

Quote from: gusto on October 13, 2005, 07:40:59 PM
i got it to work except for 9^11, too large a number...

With better structured code it wouldn't be an issue...

Quote from: gusto on October 13, 2005, 07:40:59 PM
the way my code works isnt exactly what i wanted, i am going to keep working on it, but atleast i will get some credit for this....

Sure it isn't, because I believe you don't know for yourself what that thread (or better: threat) of code does.
Yes, you'll get credits. But do you really want negative ones?  :wink

Quote from: gusto on October 13, 2005, 07:40:59 PM
can anybody help me on how to avoid adding the integers and just using the eax register and my variable y...

With procedures and loops (using conditional jumps, not with the loop mnemonic) you'll achieve your goal.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

Eóin

Quote from: gusto on October 13, 2005, 03:41:48 AM
how is it multiplying by 8, if that number is never even mentioned? i thought all i was doing was adding 9's in loops.. now im even more lost lol  ::)
Did you copy this code from someone then :naughty: ?

The bit;
mov eax,y
add y,eax


Adds y to itself, effectivly doubleing it, when you do this three times in a row you effectivly multiply by 8. Now it'll take just a small step forward to modify that into multiplication by 9.

Go back to the code with the loop, its much cleaner. I know Raymond mentions you should use conditional jumps ands he's correct, but loop will be able to get the job done for the mo. Posting big long listing here won't get you much help cause don't forget people here have no access to the writedec or crlf functions, we're debugging your code by running it in our heads not on a machine, so we like small bitsized chunks. Hence why Raymond keeps saying; "Write a procedure...".

gusto

Quote from: Eóin on October 13, 2005, 09:49:11 PM
Quote from: gusto on October 13, 2005, 03:41:48 AM
how is it multiplying by 8, if that number is never even mentioned? i thought all i was doing was adding 9's in loops.. now im even more lost lol  ::)
Did you copy this code from someone then :naughty: ?

The bit;
mov eax,y
add y,eax


Adds y to itself, effectivly doubleing it, when you do this three times in a row you effectivly multiply by 8. Now it'll take just a small step forward to modify that into multiplication by 9.

Go back to the code with the loop, its much cleaner. I know Raymond mentions you should use conditional jumps ands he's correct, but loop will be able to get the job done for the mo. Posting big long listing here won't get you much help cause don't forget people here have no access to the writedec or crlf functions, we're debugging your code by running it in our heads not on a machine, so we like small bitsized chunks. Hence why Raymond keeps saying; "Write a procedure...".

ah ok, the 8* makes sence now that u explained it.. and no the code is mine, but its from a structure the prof. gave us, its the only thing im workin off from... i dont know how u write procedures or the proto thing, i tried but jus get errors after errors... thanks

gusto

i got my code to work with the structure my prof. gave me... i tried doing everything you guys told me, but my lack of assembler knowledge got the best of me... i'll be back with more questions for my next project  :dazzled:....

include \masm615\include\irvine16.inc


.data
x               dword  9

.code
main  proc
startup
mov  eax,1
call  writedec
call  crlf
mov  ecx,11



lp:             mov  eax,x
add  x,eax
call  writedec
call  crlf
add  x,eax
mov  eax,x
add  x,eax
add  x,eax
loop  lp

exit
main            endp
end  main


gives me array of 9^0 to 9^11 (9^11 not fitting, but prof. said that would happen) using only addition....

Eóin

Don't be so hard on yourself, its working now, be proud of that :U .

mnemonic

Quote from: gusto on October 13, 2005, 11:23:29 PM
i got my code to work with the structure my prof. gave me... i tried doing everything you guys told me, but my lack of assembler knowledge got the best of me... i'll be back with more questions for my next project  :dazzled:....

Your last post looks quite good - even without comments.
Keep it as a reminder for yourself: If you look at your code in a few years you wish you had placed comments at the time you coded it - especially if it's assembly code.

Keep on asking, it's one of the few ways to learn.
And please, don't get me wrong  :wink

Quote from: gusto on October 13, 2005, 11:23:29 PM
gives me array of 9^0 to 9^11 (9^11 not fitting, but prof. said that would happen) using only addition....

That's it.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way