Translating a C program to IA32 assembly language....

Okay so I have a C program, I now need to translate it to IA32 assembly languae..seems simple enough, except one thing... I have no idea where to start I have never even touched or worked with assmebly language.. so now i need to figure out what i need to do.. heres the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
int month, numDays, year;
int valid = 1;
int main() {
printf("Enter month as an integer (1-12): ");
scanf("%d", &month);
printf("Enter year (e.g., 2012): ");
scanf("%d", &year);
switch (month) {
case 1: case 3: case 5:
case 7: case 8: case 10:
case 12:
numDays = 31;
break;
case 4: case 6:
case 9: case 11:
numDays = 30;
break;
case 2:
if ( ((year % 4 == 0) &&
!(year % 100 == 0))
|| (year % 400 == 0))
numDays = 29;
else
numDays = 28;
break;
default:
valid = 0;
printf("Invalid month.\n");
}
if (valid)
printf("%d/%d has %d days\n", month, year, numDays);
}
Just tell your compiler to produce assembler output (-S for gcc and compatible compilers).
If you have never done assembler before, I would start with something much smaller ................

I mean it, assembler is a bit of a nightmare - prepare for brain hurts !!!
Remember when you first started programming, hopefully you did a "hello world" program.

Do the same for assembler.

Next, add a simple if statement.

Then add an else if clause.

Move on to a simple loops - for while etc, and a switch.

Try putting more complicated conditions.

Try a basic function.

Hope all goes well, I wish you you really good luck. Go buy some aspirin !!! And coffee.
Keep in mind that your C program calls several library routines from <stdio.h> (printf, scanf). Are you going to continue to rely on the C run-time library, or do also need to provide that functionality in IA32?
Topic archived. No new replies allowed.