inline asm

Jan 13, 2010 at 7:28pm
Hello guys,

I'm trying to insert some inline asm codes into a project but I have a doubt about it, for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main ()

{

        int i=2;

	_asm mov eax,i
	_asm sub eax,1
	_asm mov i,eax

	cout << i << endl; 

    cin.get();
    return 0;
    
}


The code is working fine and the int i contains 1 as we can see, is there some way to return the that decimal value in binary value? (which would be 00000000000000000000000000000001 in a 32-bit format)

If yes, how should I declare the new variable to store the binary value?
a bitset?

Regards,
Jan 13, 2010 at 8:22pm
'i' is not decimal, the output is. 'i' is really binary already, but 'cout' converts it to decimal. I'm sure there is some way to do this with the standard libraries, but I don't know what it is.
Something like this should work, I think...
1
2
3
for(int p = 0; p < 32; p++){
    cout<<i & (1<<p);
}


Also, this question has nothing to do with assembly.
Jan 13, 2010 at 8:57pm
Thanks for the reply hamsterman,

In fact everything in computer is binary stuffs, including this message I'm writing.

I used a very simple example just to exemplify what I was asking, I'm plaining to insert something much more complex and it will return me an array of bitmaps.

My question was: how to "display" any value in binary value?

And you said: "Also, this question has nothing to do with assembly."

Well..

_asm mov eax,i
_asm sub eax,1
_asm mov i,eax

You are right, perhaps I should ask what means these lines in a VB forum.
Jan 13, 2010 at 10:05pm
i--;
Topic archived. No new replies allowed.