This is I wrote,
Why will only output a blank square?
CodePudding user response:
# include & lt; stdio.h>
Void DecToBin (int n, char [] b);
Int main (void)
{
int n;
Char [99] b={0};
The scanf (" % d ", & amp; N);
DecToBin (n, b);
return 0;
}
Void DecToBin (int n, char [] b)
{
Int k, j, I=0;
While (n!=0)
{
//b [I]=n % 2;
[I]=n % 2 b + '0'.
N=n/2;
i++;
}
B [I]='\ 0';
//for (j=I - 1; J & gt;=0; J++)
For (j=I - 1; J & gt;=0; J -)
{
Printf (" % c "[j]. B);
}
}
CodePudding user response:
Void DecToBin (int n, char [] b){
The __asm
{
Mov edx, n
Mov edi, b
Xor ecx, ecx
BSR ecx, edx
Inc ecx
Ror edx, cl
NEXT:
Xor al, al
SHL edx, 1
The adc al, 30 h
Stosb
Loop NEXT
Xor al, al
Stosb
}
Puts (b);
}
CodePudding user response:
GCC version
Void DecToBin (int n, char [] b)
{
__asm__ (
"Movl % 0, % % edx;"
"Movl % 1, % % edi;"
"Xorl % % ecx, % % ecx;"
"BSR % % edx, % % ecx;"
"The inc % % ecx;"
"Cl rorl % % % % edx;"
"NEXT,"
"Xor % % al, % % al;"
SHL $1, % % edx; ""
"Adcb $0 x30, % % al;"
"Stosb;"
"Loop NEXT;"
"Xor % % al, % % al;"
"Stosb;"
: : "m" (n), and "m" (b)
);
Puts (b);
}