Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Well guys, it looks like I'll be asking the questions now. Anyway, I need some help with some Intel assembly in a MSVC++ environment. Let me explain my situation before you say anything. So far the assembly learning process is driving me nuts, and my proff is no help either. I am trying to make use of this book and whatever resources I have, and coming to this forum is always my last resort (of which I am down to now).
So what I want to try and do is get two variables and add them in assembly, with the I/O handled in C++. Then using assembly, I want to move num1 into an eax register, then take num2 and add it to the eax register. Did that make any sense to you guys? Here's some code and I hope this clarifies what I am trying to do:
#include <iostream>
using namespace std;
int main()
{
int num1,num2;cout << "Enter a number: " << endl;
cin >> num1;
cout << endl;cout << "Enter another number: " << endl;
cin >> num2;
cout << endl;__asm
{
mov eax,num1
add eax,num1
}cout << num1 << endl;
cout << endl;return 0;
}Also I want to be able to print this value in the register to the console, with of course C++ (if at all possible). This is not part of the assignment, I am just trying to get used to programming with assembly. I am going crazy trying to find some good tutorials on the net, and I have a 32 bit cascading decoder circuit to work on as well. Agh! We do all of this to fix lamps, sheesh! 8) j/k. Thanks in advance for the help, if any should be so willing to come my way.
- Rolos

here some useful links:
http://asmsource.8k.com/
http://webster.cs.ucr.edu/Page_asm/ArtOfAsm.html
http://www.movsd.com/
http://www.eskimo.com/~htak/win32asm/index.html

As far as I know, add gets 2 registers as its arguments. Are u sure num1 is stored in a register? Also are u sure that the result of add is stored in its second argument?

I can't believe no one posted this link:
http://webster.cs.ucr.edu/Page_asm/ArtOfAsm.htmlHere are multiple examples:
http://www.planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?lngWId=3&B1=Quick+Search&optSort=Alphabetical&txtCriteria=inline+assembly&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUEThis one is just what you want (sub, add same syntax).
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1222&lngWId=3{
int x,y,rt;
cout << "enter number 1: ";
cin >> x;
cout << "\nenter number 2: ";
cin >> y;
_asm
{
mov eax,x
mov ebx,y
sub eax,ebx /*Let's add there instead*/
mov rt,eax
}
cout << "\nresult: " << rt;
}
Check section 2.8 of the ArtofAsm for the same idea - only pure assembly without MSVC++, so not really not the best tutorial.Remember asm is supposed to take about 3x longer than C/C++ (so they say).
As a side, x86 is going out sooner than anyone thinks. MIPS-like instruction sets are not only in vogue, they are superior in scaling, provide simpler backwards compatibility, and make branch prediction a little more reliable. AMD is modifying x86 with their Opteron (extending it). Intel is just waiting for the day when they can send the architecture to dev/null, but they cannot bring down the prices of their Itanium (large initial investment, should pay off though).
Someone needs to retire x86 ISA. At least you don't have any constraints put on your assembly by the compiler (as opposed to GCC).

anonproxy,
"You da man"! I am always amazed with all of the sources and knowledge that you pour into each comment. You should kick Bill out and run Microsoft 8) Thank you so much, it made my search much easier and I understand much more about the assembly.
- Rolos

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |