Coldfire assembler

Dec 13, 2003 11 Replies

Hello group,



does anybody of you know an easy way to get the 2nd power of an unsigned



16-bit number (eg. 2^2 = 4) No flags needed. After reading the Spec-sheet the only way I can think of is a loop. I am new to assembler so maybe my "C-thinking" hides an easier way.

Thanks a lot



Kai


Since anything larger than 256^2 will blow your 16 bit uint, why not use a

512 byte lookup table? :^P
Ron Sharp.

Because - I confess - it is homework :-)) I know how to do it with loops, but given the (little) points you can get there must be an easier way to do it. It just makes me mad.

Anyway. If anybody could give me a hint that would be nice.

Good night

Kai

Have you really thought about what taking the second power of something really means?

Let me just say your solution is one instruction. No loops needed.

Combining that with (16*a + b)^2 = 256*a^2 + 32 * a * b + b^2 with a and b 4 bit quantities, you can use some 16 entry tables and a single multiplication.

Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. USE worldnet address!

Is there something I'm not understanding here? He just wants to square a 16-bit unsigned number, right? And this is Coldfire, which is the 68000 CPU, right? Can't he accomplish this with just a single multiplication?

Kai, read the Coldfire Programmer's Reference Manual, Chapter 4: Integer User Instructions.

You will find the solution there.

/jan

Kai Schülke schrieb in im Newsbeitrag: brg1dn$enm$ snipped-for-privacy@lacerta.tiscalinet.it...

Thanks to all!!!

After having slept a night and read your coments it's obvious that it's only a single multiplication. I felt that there must be an easy way. If the easy one won't work I'll switch to the lookup-tables :-))

Thanks a lot, again

Bye

Kai

No, I think you understand it completely.

Casey

Ok, thanks. Sometimes(ok, maybe many times) there's a subtlety that I've missed.

Well, I do my share of that as well.

Casey

Just use multiplly.

My contribution to future homework assignments :)

Also, the following articles will help you in learning ColdFire (68000) assembly.

formatting link

formatting link

formatting link

Sandeep

--

formatting link
EventStudio 2.0 - Go beyond UML Sequence Diagrams and Use Case Diagrams

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required