我试图用汇编语言(nasm,ubuntu)编写一个简单的程序来添加2个数字。我坚持这个错误
错误:行开头预期的标签或说明
我在运行在线编译器上的代码时没有遇到上述错误。但是如果尝试在ubuntu环境中运行相同的代码,那么我就会遇到错误提及。
代码I使用
;The following Program performs addition of two numbers
section .data
msg1 db 'Enter 1st digit: ', 0xa
len1 equ $-msg1
msg2 db 'Enter 2nd digit: ', 0xa
len2 equ $-msg2
msg3 db 'The sum is: '
len3 equ $-msg3
section .bss
num1 resb 2
num2 resb 2
res resb 1
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ebx, 1
mov ecx, msg1
mov edx, len1
mov eax, 4
int 0x80
mov ebx, 0
mov ecx, num1
mov edx, 2
mov eax, 3
int 0x80
mov ebx, 1
mov ecx, msg2
mov edx, len2
mov eax, 4
int 0x80
mov ebx, 0
mov ecx, num2
mov edx, 2
mov eax, 3
int 0x80
;O/Ps "The sum is:"
mov ebx, 1
mov ecx, msg3
mov edx, len3
mov eax, 4
int 0x80
;moving the first number to eax register and second number to ebx and subtracting ascii '0' to convert it into a decimal number
mov eax, [num1]
sub eax, '0'
mov ebx, [num2]
sub ebx, '0'
;add eax & ebx then add '0' to convert the sum from decimal to ASCII
add eax, ebx
add eax, '0'
;storing the sum in memory location res
mov [res], eax
;print the sum
mov ebx, 1
mov ecx, res
mov edx, 1
mov eax, 4
int 0x80
;Exit
mov eax, 1
int 0x80