Page 1 of 1

mov operand type mismatch problem

Posted: Thu Jan 31, 2019 6:56 pm
by MakaAlbarn001
I'm trying to enable paging. For some reason, I keep getting this error:

Code: Select all

make[1]: Entering directory '/mnt/c/Users/tim21/Projects/firststep/arch/i686'
i686-elf-as paging_init.s -o paging_init.o
paging_init.s: Assembler messages:
paging_init.s:17: Error: operand type mismatch for `mov'
Makefile:14: recipe for target 'paging_init.o' failed
make[1]: *** [paging_init.o] Error 1
make[1]: Leaving directory '/mnt/c/Users/tim21/Projects/firststep/arch/i686'
Makefile:28: recipe for target 'arch.o' failed
make: *** [arch.o] Error 2
here is my assembly code:

Code: Select all

.section .text

.global loadPageDirectory
loadPageDirectory:
    push %ebp
    mov %esp, %ebp
    mov 8(%esp), %eax
    mov %eax, %cr3
    mov %ebp, %esp
    pop %ebp
    ret

.global enablePaging
enablePaging:
    push %ebp
    mov %esp, %ebp
    mov %cr0, $eax
    or $0x80000000, %eax
    mov %eax, %cr0
    mov %ebp, %esp
    pop %ebp
    ret
Can anyone help me with this?

Re: mov operand type mismatch problem

Posted: Thu Jan 31, 2019 7:11 pm
by pat
MakaAlbarn001 wrote:I'm trying to enable paging. For some reason, I keep getting this error:

Code: Select all

paging_init.s:17: Error: operand type mismatch for `mov'
In cases like these, always examine what the tool is trying to point out to you. Look closely at line 17, and then compare it to line 18. Pay attention in particular to the prefix symbols.

Re: mov operand type mismatch problem

Posted: Fri Feb 01, 2019 12:41 am
by iansjack
"$eax"?

Re: mov operand type mismatch problem

Posted: Fri Feb 01, 2019 12:45 am
by MichaelPetch
Yes, it should be %eax, not $eax

Re: mov operand type mismatch problem

Posted: Fri Feb 01, 2019 8:05 am
by fpissarra
Since you are dealing with AT&T assembly style, it is imperative to use the correct mnemonics: movl, movw or movb instead of mov.

The same applies to push/pop, "or", ...

And, of course, as pointed out: $eax is wrong too.

Re: mov operand type mismatch problem

Posted: Fri Feb 01, 2019 8:58 am
by Octocontrabass
fpissarra wrote:Since you are dealing with AT&T assembly style, it is imperative to use the correct mnemonics: movl, movw or movb instead of mov.
Not really. When the assembler can infer the operand size from the operands, you may use "mov" without a suffix.

Re: mov operand type mismatch problem

Posted: Fri Feb 01, 2019 11:48 am
by MichaelPetch
Octocontrabass wrote:Not really. When the assembler can infer the operand size from the operands, you may use "mov" without a suffix.
My personal coding preference when using AT&T syntax isn't to use the instruction suffixes unless they can't be inferred.