Assembly language error with the mov instruction

288 Views Asked by At

I am receiving an error that says unsupported instruction `mov'. The error is the line under #output in the inout: function.

.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

How can I fix this error?

1

There are 1 best solutions below

1
SinePost On

You are attempting to move 64 bits to a register that can only hold 32. While the reverse is possible, this is an impossible operation without truncating the source. Consider using mov %eax, %edi or mov %rax, %rdiso that both the source and destination registers will be the same size.