Click here to Skip to main content
15,665,276 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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?  ");
        printf("How many total calories are in one serving?  ");

        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
Updated 29-Jul-20 23:30pm

1 solution

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[^].
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900