Thread: C to y86

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    44

    C to y86

    I don't know if this is the correct place to post this, but here goes...

    I am trying to get this program:
    Code:
    #include <stdio.h>
    
    int main() {
    
    	int A[4]={1,2,3,4};
    	int B[4]={4,3,2,1};
    
    	int dot;
    	dot=A[0]*B[0]+A[1]*B[1]+A[2]*B[2]+A[3]*B[3];
    
    	printf("%d", dot);
    
    }
    to y86. This is what I have:

    Code:
    	.pos 0
    
    
    .LC0:
    	.string	"%d\n"
    	.text
    .globl main
    	.type	main, @function
    main:
    	pushl	%ebp
    	rrmovl	%esp, %ebp
    	andl	$-16, %esp
    	pushl	%ebx
    	subl	$76, %esp
    	irmovl	$1, 44(%esp)
    	irmovl	$2, 48(%esp)
    	irmovl	$3, 52(%esp)
    	irmovl	$4, 56(%esp)
    	irmovl	$4, 28(%esp)
    	irmovl	$3, 32(%esp)
    	irmovl	$2, 36(%esp)
    	irmovl	$1, 40(%esp)
    	mrmovl	44(%esp), %edx
    	mrmovl	28(%esp), %eax
    	imull	%eax, %edx
    	mrmovl	48(%esp), %ecx
    	mrmovl	32(%esp), %eax
    	imull	%ecx, %eax
    	leal	(%edx,%eax), %ebx
    	mrmovl	56(%esp), %edx
    	mrmovl	40(%esp), %eax
    	imull	%eax, %edx
    	mrmovl	52(%esp), %ecx
    	mrmovl	36(%esp), %eax
    	imull	%ecx, %eax
    	leal	(%edx,%eax), %eax
    	leal	(%ebx,%eax), %eax
    	rmmovl	%eax, 60(%esp)
    	irmovl	$.LC0, %eax
    	mrmovl	60(%esp), %edx
    	rmmovl	%edx, 4(%esp)
    	rmmovl	%eax, (%esp)
    	call	printf
    	addl	$76, %esp
    	popl	%ebx
    	rrmovl	%ebp, %esp
    	popl	%ebp
    	ret
    
    	.pos 0x100
    Stack:
    But I am getting missing colon errors on my simulator. There aren't colons in y86 other than the loops, any suggestions?

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    It looks like you just took the output of gcc -S and modified some instruction names. Have you verified that this is valid input to the assembler you're using?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    44
    I haven't, but I followed step by step instructions using the assembler.

    I just learned that leal and imull aren't commands, so it'll give me that error. However, I don't know how to convert the x86 commands leal and imull to y86. My book is terrible.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You have to look up what they do and find alternate commands for them. There are plenty of references to both languages on the net.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Tags for this Thread