#include <stdio.h>
#include <math.h>
#include <string.h>
#define N 100
void exit();
int main()
{
        int n,n1,n2,bin[100],i,j;
	printf("Enter Decimal: \t\t");
	scanf("%d",&n);
	n=n;
	n1=n;
	n2=n;
	printf("\nEquivalent Binary:\t",n);
	for(i=0;n!=0;i++)
	{
		bin[i]=n%2;
		n=n/2;
	}
	for(j=i-1;j>=0;j--)
	{
		printf("%d",bin[j]);
	}
	
	printf("\nEquivalent Octal:\t",n1);
	int r[10];
	for(i=0;n1!=0;i++)
	{
		r[i]=n1%8;
		n1=n1/8;
	}
	i--;
	for(;i>=0;i--)
	{
		printf("%d",r[i]);
    }
    
    
	printf("\nEquivalent Hex: \t",n2);
    for(i=0;n2!=0;i++)
	{
		r[i]=n2%16;
		n2=n2/16;
	}
	i--;
	for(;i>=0;i--)
	{
		if(r[i]==10)
			printf("A");
		else if(r[i]==11)
			printf("B");
		else if(r[i]==12)
			printf("C");
		else if(r[i]==13)
			printf("D");
		else if(r[i]==14)
			printf("E");
		else if(r[i]==15)
			printf("F");
		else
			printf("%d",r[i]);
	}
    printf ("\n\nPress Any Key to Continue...\n");
    getch();
    exit (0);
    return (0);

well, i have this .c code... and im trying to convert it to assembly... and i cant seem to figure out where to start... can you guys help me out...

Recommended Answers

All 4 Replies

This is the best I can do until you start to post your own realistically attempted code.

Bite sized chunks.
Make your ASCII and integer print functions then test!

Try to rework your functions in C into a simpler form!
You can use an ASCII table

char szHex[] = "0123456789ABCDEF"

or

if digit <= 9
    c = digit + '0'
else
    c = digit + 'A' - 10

Note the difference between '0' 0x30 and 'A' 0x41 is 0x11

if (digit > 9) digit += 0x11      'A'-'0'

c = digit + '0'

or branchless!

c = (10 - digit) >> 15        ;   15 if 16-bit integers
c &= ~0x11
c += '0' + digit

This is C question, then it haves to be in C/C++ Forum here in DaniWeb.

No, no, no! It is not a C question. It is an Assembly question, but the code is far away from being clearly seen as assembly code.

ALWAY write you assembly code in a Higher level language such as (C) not C++ and make it lite weight and clear there first. That's all that needs to be done here first. Rework this C code to be simpler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.