-
Assembler - binary
Can anyone help me out with this, b v.greatful. I'm trying to convert a given int to a binary number. I can output the data by dividing the num by 2 each time, e.g
10/2 = 0
5/2 = 1
2/2 = 0
1/2 =1
Program outputs 0101, but this has to be revesed so 1010. any ideas? Please!!!
void DecBinary(short int Num1)
{
short int Temp,Answer=0;
asm
{
mov ax,Num1;
mov Temp,ax;
Binary:
mov Answer,0;
mov bx,2;
xor ax,ax;
mov ax,Temp;
div bl;
mov bl,al //get whole no out of al
mov Temp,bx;
cmp ah,0;
jz NotNum;
jmp Next;
NotNum:
inc Answer;
}
asm
{
Next:
}
cout << Answer;
asm
{
cmp Temp,0;
jne Binary;
}
}
-
help for ya
you could use push/pop to push the # on stack and then pop the # off when you need to. The would display in opposite order...that is just one way to do it
-
An example -
Code:
#include <cstdio>
using namespace std;
int main()
{
int i = 123;
char* form = "%d";
_asm
{
mov eax,i
mov ecx,32
bin:
mov ebx,eax
and ebx,0x00000001
push ebx
shr eax,1
loop bin
mov ecx,32
print:
pop eax
mov ebx,form
push ecx
push eax
push ebx
call printf
add esp,8
pop ecx
loop print
}
return 0;
}
-
Thanks
Thanks for everyones help. Tried push and pop, works on win98 my system, but crashes on an nt system. can't understand why???
Anyway cheers.
-
What language is that (Assembly) and where can i read up on it?
I see it when I use my debug program.
-
Read this. It's pretty good. But, you have to come here to get it cause it is over the limit for a file size. http://www.flashdaddee.com/forums/sh...&threadid=1235
-