• 0

Assembly x86 Multiply and Divide two number 16 bits


Question

I admit that I am very new to this language and I'm completely clueless about this stuff. I tried to learn by myself but I got a lot of difficulty. So, please help me if you can, I really appreciate that.

Here is the question that I want to discuss about:

Write a program that calculates the value of x using these two formulae:

w = (22102 * -12)/(18 ? 3)

x = (12032/w) * (2354 + 34)

Use the properly-sized signed or unsigned operands as appropriate. Demonstrate that your answer is correct by using the debugging software to walk through the program instruction by instruction. Take a screen shot of the debugging window that shows the value of every register and the named memory locations after each instruction executes.

Can you please help me about that?

Thank you very much.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Do you know any assembly?

This sounds a lot like an assignment so I'm not going to post the answer in code but http://www.cyberarmy.net/library/article/1652 will give you an idea on the basics of assembly and then you can just google for all the assembly commands.

As a general rule for this you will just be moving values between registers e.g. MUL(R1, R2, R3). This will multiply the value in R2 by the value in R3 and place the answer in R1.

Any negative values will be encoding in binary Two's Compliment form; google it.

An assembly debugger (e.g. http://ald.sourceforge.net/)will be needed to do your screen grabs.

Hope that helps.

Chris

Link to comment
Share on other sites

  • 0
w = (22102 * -12)/(18 ? 3)

x = (12032/w) * (2354 + 34)

x86 is a RISC so doing that will be difficult.

There are 2 ways to approach this,

1) Cheat. Put that into a C program and then disassemble it. (GDB, IDA PRO, etc)

Obviously, using this method you would have to cut out the unwanted assembly the compiler tosses in there.

2) Look at http://en.wikipedia.org/wiki/X86_instruction_listings for reference.

Using that,

;(22102 * -12)

MOV $eax, 22102

IMUL $eax, $eax, -12

;(18-3)

MOV $edx, 18

ADD $edx, $edx, -3

;w = (22102 * -12)/(18-3)

IDIV $eax, $eax, $edx; w is in eax

;feel free to store it in memory or push it into a stack

now that ive done W, you can do X with ease.

hint: multiplying 2 32-bit numbers will result in a 64bit number, so its more efficient to load the 16bit registers (ax, dx, etc) instead of the 32 bit registers(eax, edx, etc).

Link to comment
Share on other sites

  • 0
1) Cheat. Put that into a C program and then disassemble it. (GDB, IDA PRO, etc)

Obviously, using this method you would have to cut out the unwanted assembly the compiler tosses in there.

Chances are there will be a lot of it. Any lecturer should be able to tell quite easily that the solution wasn't created using assembly. And anyway, if this is one of the easier assignments, it doesn't help you any for the more difficult ones.

The advice so far seems pretty solid for solving the problem. Also, whenever I've programmed Assember for University work, we used a tool called MPLAB. It's has the ability to step through code, and the stopwatch function, which is a great tool for checking the execution time of your program if you ever need to.

Link to comment
Share on other sites

  • 0

Can anyone please help me with the code and I will learn through it. I google it a lot but I couldn't get appropriate answer. I am not trying to cheat or something, it's a practice assignment and there is no answer in the book, that's why I asked for help.

Thanks for all advices.

Link to comment
Share on other sites

  • 0

Dude, if between chrismaddern's and ekw's extremely helpful posts you find yourself still unable to do this problem then you should either:

1) Speak with your Professor/TA during office hours for help

or

2) Consider taking a different class since you don't seem up to the challenge of learning this material

Seriously, big kudos to chrismaddern and ekw. They've shown you the door, but you need to open it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.