0

So let's say that we have two registers that contain the following hexadecimal values: AB0890C2, 4598EE50. What would be the result of adding them using MMX instructions:

a. for packed byte
b. for packed word

Assuming saturation arithmetic is not used?

From my understanding, if you add the two hex values normally, you get F0A17F12, but how would I add this using MMX instruction for both the packed byte and word?

Paul R
  • 208,748
  • 37
  • 389
  • 560
k-Rocker
  • 147
  • 2
  • 9
  • Is there some reason why it has to be MMX ? Since you just have two 32 bit values it would probably be easier to use [SWAR](https://en.wikipedia.org/wiki/SWAR) for this. – Paul R Nov 11 '15 at 07:51
  • The question is from my textbook, and it stated to use MMX instruction. – k-Rocker Nov 11 '15 at 16:00
  • 1
    You might want to throw that book out (MMX has been obsolete for 20 years) and get something a bit more up-to-date. If it's for school though and you have no choice then look at the MMX intrinsics [here](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=MMX), particularly `_mm_add_pi8` and `_mm_add_pi16`. – Paul R Nov 11 '15 at 16:33
  • unfortunately, it is for school, so i cant throw it out :) – k-Rocker Nov 11 '15 at 16:49
  • Do you need to write actual code for this or do you just need to say what the result would be in each case ? – Paul R Nov 11 '15 at 17:49
  • I believe I need to show my work, but i need the results – k-Rocker Nov 11 '15 at 17:57
  • OK - so pretty simple then - is there a particular aspect of this that you're stuck on ? – Paul R Nov 11 '15 at 18:36
  • Well, i know how to add the hex normally, but im not sure how i would show it using MMX code and for each of the packet – k-Rocker Nov 11 '15 at 20:02
  • OK - just break each 32 bit value up into bytes or words and then add each corresponding pair of bytes or words and ignore any carries. – Paul R Nov 11 '15 at 22:10
  • ok so for the byte, i divide the hex into 8 parts and the word into 2 correct? and without the carry, for example F + F = E right instead 1E? – k-Rocker Nov 11 '15 at 22:34
  • You have 32-bit values, so every one contains 4 bytes or 2 words. MMX register is 64-bit though. – MBo Nov 12 '15 at 05:45
  • As @MBo says, each byte corresponds to two hex digits, so you need to start by adding `C2` and `50` for the byte case, and so on. – Paul R Nov 12 '15 at 06:43

1 Answers1

1

I am assuming that you can get them into MMX registers.

This adds them as if they were double numbers

paddd mm0, mm1

This adds them as if they were bytes

paddb mm0, mm1