Thread: C to y86

  1. #1
    Registered User
    Join Date
    Oct 2009

    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:
    #include <stdio.h>
    int main() {
    	int A[4]={1,2,3,4};
    	int B[4]={4,3,2,1};
    	int dot;
    	printf("%d", dot);
    to y86. This is what I have:

    	.pos 0
    	.string	"%d\n"
    .globl main
    	.type	main, @function
    	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
    	.pos 0x100
    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
    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
    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
    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