我收到了一个错误,内容是不支持指令'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
如何修复此错误?
1条答案
按热度按时间mf98qq941#
您正试图将64位移到只能容纳32位的寄存器中。虽然可以执行相反的操作,但如果不截断源,则无法执行此操作。请考虑使用
mov %eax, %edi
或mov %rax, %rdi
,以便源寄存器和目标寄存器的大小相同。