Advertisement
AntonioVillanueva

Suma dos numeros de 16 bits obteniendo el resultado en 32bit

Feb 2nd, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. //Suma dos numeros de 16 bits obteniendo el resultado en 32bits
  2. // NOTA unsigned short  2 bytes ,unsigned int 4 bytes
  3. // movzwl copia de word a long completando con ceros ....
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. unsigned int suma (unsigned short numA ,unsigned short numB){
  8.     unsigned int numRes(0);
  9.     asm(
  10.     "movzwl %[numA],%%eax \n\t"/* move word to long */
  11.     "movzwl %[numB],%%ebx \n\t"
  12.     "add %%ebx,%%eax \n\t"/* suma eax=eax+ebx*/
  13.     "mov %%eax,%[numRes] \n\t"/* numRes=eax */
  14.    
  15.     :[numRes]"=r"(numRes)
  16.     :[numA] "r"(numA),[numB] "r" (numB)
  17.     ); 
  18.    
  19.     return numRes;
  20. }
  21. int main (){
  22.  
  23.     cout <<suma (65535,65535);//131072
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement