assembly mov指令的汇编语言错误

tnkciper  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(214)

我收到了一个错误,内容是不支持指令'mov'。错误位于输入输出中#output下的行:功能。

.data
msg:     .string "Assignment 2: inout\n"

#ifndef MACOS
.ifndef CODEGRADE
    .global main
    main: jmp my_main
.endif
#else
    .global _main
    _main: jmp my_main
    printf: jmp _printf
    scanf: jmp _scanf
    exit: jmp _exit
#endif

.text

.global my_main                         # make my_main accessible globally
.global my_increment                    # make my_increment accessible globally

my_main:
        # set up the stack frame
        push    %rbp
        mov     %rsp, %rbp

        #print message
        mov     $msg, %rdi
        call    printf

        call    inout                

        # clear the stack and return
        xor     %rax, %rax
        leave
        ret

inout:
        # read input and increment the value
        mov     $0, %rax
        call    scanf           # read input
        call    my_increment    # increment input

        # output 
        mov     %rax, %edi      # move incremented value to edi for output
        xor     %eax, %eax      # clear eax to prepare for output
        jmp     printf          # jump to printf for output

my_increment:
        add     $1, %rdi        # increment the input value by 1
        mov     %rdi, %rax      # move the result to rax for return
        ret                     # return to the caller

如何修复此错误?

mf98qq94

mf98qq941#

您正试图将64位移到只能容纳32位的寄存器中。虽然可以执行相反的操作,但如果不截断源,则无法执行此操作。请考虑使用mov %eax, %edimov %rax, %rdi,以便源寄存器和目标寄存器的大小相同。

相关问题