#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Can someone run my code through a compiler to convert to IA32


    Wrote out this code, but I dont have a C compiler on my computer at home and I need it to be converted into IA32 Assembly language...


    #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);
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    Are you sure this is C? The main function has an implied return 0.

    Here's the IA32
    Code:
    	.file	"test.c"
    	.comm	month,4,4
    	.comm	numDays,4,4
    	.comm	year,4,4
    	.globl	valid
    	.data
    	.align 4
    	.type	valid, @object
    	.size	valid, 4
    valid:
    	.long	1
    	.section	.rodata
    	.align 4
    .LC0:
    	.string	"Enter month as an integer (1-12): "
    .LC1:
    	.string	"%d"
    .LC2:
    	.string	"Enter year (e.g., 2012): "
    .LC3:
    	.string	"Invalid month."
    .LC4:
    	.string	"%d/%d has %d days\n"
    	.text
    	.globl	main
    	.type	main, @function
    main:
    .LFB0:
    	.cfi_startproc
    	pushl	%ebp
    	.cfi_def_cfa_offset 8
    	.cfi_offset 5, -8
    	movl	%esp, %ebp
    	.cfi_def_cfa_register 5
    	pushl	%ebx
    	andl	$-16, %esp
    	subl	$16, %esp
    	movl	$.LC0, %eax
    	movl	%eax, (%esp)
    	.cfi_offset 3, -12
    	call	printf
    	movl	$.LC1, %eax
    	movl	$month, 4(%esp)
    	movl	%eax, (%esp)
    	call	__isoc99_scanf
    	movl	$.LC2, %eax
    	movl	%eax, (%esp)
    	call	printf
    	movl	$.LC1, %eax
    	movl	$year, 4(%esp)
    	movl	%eax, (%esp)
    	call	__isoc99_scanf
    	movl	month, %eax
    	cmpl	$12, %eax
    	ja	.L2
    	movl	$1, %edx
    	movl	%edx, %ebx
    	movl	%eax, %ecx
    	sall	%cl, %ebx
    	movl	%ebx, %eax
    	movl	%eax, %edx
    	andl	$5546, %edx
    	testl	%edx, %edx
    	jne	.L3
    	movl	%eax, %edx
    	andl	$2640, %edx
    	testl	%edx, %edx
    	jne	.L5
    	andl	$4, %eax
    	testl	%eax, %eax
    	jne	.L4
    	jmp	.L2
    .L3:
    	movl	$31, numDays
    	jmp	.L6
    .L5:
    	movl	$30, numDays
    	jmp	.L6
    .L4:
    	movl	year, %eax
    	andl	$3, %eax
    	testl	%eax, %eax
    	jne	.L7
    	movl	year, %ecx
    	movl	$1374389535, %edx
    	movl	%ecx, %eax
    	imull	%edx
    	sarl	$5, %edx
    	movl	%ecx, %eax
    	sarl	$31, %eax
    	movl	%edx, %ebx
    	subl	%eax, %ebx
    	movl	%ebx, %eax
    	imull	$100, %eax, %eax
    	movl	%ecx, %edx
    	subl	%eax, %edx
    	movl	%edx, %eax
    	testl	%eax, %eax
    	je	.L8
    .L7:
    	movl	year, %ecx
    	movl	$1374389535, %edx
    	movl	%ecx, %eax
    	imull	%edx
    	sarl	$7, %edx
    	movl	%ecx, %eax
    	sarl	$31, %eax
    	movl	%edx, %ebx
    	subl	%eax, %ebx
    	movl	%ebx, %eax
    	imull	$400, %eax, %eax
    	movl	%ecx, %edx
    	subl	%eax, %edx
    	movl	%edx, %eax
    	testl	%eax, %eax
    	jne	.L9
    .L8:
    	movl	$29, numDays
    	jmp	.L6
    .L9:
    	movl	$28, numDays
    	jmp	.L6
    .L2:
    	movl	$0, valid
    	movl	$.LC3, (%esp)
    	call	puts
    .L6:
    	movl	valid, %eax
    	testl	%eax, %eax
    	je	.L11
    	movl	numDays, %ebx
    	movl	year, %ecx
    	movl	month, %edx
    	movl	$.LC4, %eax
    	movl	%ebx, 12(%esp)
    	movl	%ecx, 8(%esp)
    	movl	%edx, 4(%esp)
    	movl	%eax, (%esp)
    	call	printf
    .L11:
    	movl	$0, %eax
    	movl	-4(%ebp), %ebx
    	leave
    	.cfi_restore 5
    	.cfi_def_cfa 4, 4
    	.cfi_restore 3
    	ret
    	.cfi_endproc
    .LFE0:
    	.size	main, .-main
    	.ident	"GCC: (GNU) 4.6.3"
    	.section	.note.GNU-stack,"",@progbits

IMN logo majestic logo threadwatch logo seochat tools logo