Click here to Skip to main content
14,427,400 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hey, how do I convert this code into assembly in dev c++

#include <stdio.h>

#define CALORIES_PER_GRAM 9.0   /* there are 9 calories per gram of fat */

int main (void)
{
        int     grams_of_fat,   /* number of grams of fat in one serving */
                total_calories; /* number of calories in one serving */
        float   fat_fraction,   /* fraction of calories due to fat */
                percent;        /* percentage of total calories from fat */

        printf("This program will tell you how much of the calories in\n");
        printf("a food are from the food's fat content.\n\n");

        printf("How many grams of fat are in one serving?  ");
        scanf("%d",&grams_of_fat);
        printf("How many total calories are in one serving?  ");
        scanf("%d",&total_calories);

        fat_fraction = (grams_of_fat * CALORIES_PER_GRAM) / total_calories;
        percent = fat_fraction * 100;

        if (grams_of_fat == 1) {
                printf("\nA food with 1 gram of fat ");
        } else {
                printf("\nA food with %d grams of fat ",grams_of_fat);
        }

        if (total_calories == 1) {
                printf("and 1 calorie per serving\n");
        } else {
                printf("and %d calories per serving\n",total_calories);
        }

        printf("has %.2f%% of those calories from fat.\n\n",percent);

        return 0;
}


What I have tried:

Tried to convert c into assembly
Posted
Updated 19-May-18 12:43pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Typically you can use the compiler itself, and request it to provide the output in Assembly language, this would work on a Linux machine with GCC installed,
$ gcc program.c -S --masm=intel -o program.asm

This was of course off of my head right now, but it will work. Also, this will compile and present the Intel's version of Assembly not the AT&T, which is painful to read. :-)

Oh, and if this was an assignment to create an Assembly program for this C, then perhaps you really need to do some homework. Read the manual here, gcc(1): GNU project C/C++ compiler - Linux man page[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100