section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov eax,'3'
sub eax, '0'
mov ebx, '4'
sub ebx, '0'
add eax, ebx
add eax, '0'
mov [sum], eax
mov ecx,msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx,sum
mov edx, 1
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db "The sum is:", 0xA,0xD
len equ $ - msg
segment .bss
sum resb 1
我从这里https://www.tutorialspoint.com/assembly_programming/assembly_arithmetic_instructions.htm获取了此代码。在这段代码中,我不明白这三行的用途。
sub eax, '0'
sub ebx, '0'
add eax, '0'
请注意,在mov eax,'3'
您移动字符时-因此eax
此指令后的值为0x33(ASCII码为“ 3”)。通过减去(再次)'0'
字符(即0x30),可以将数字字符转换为其实际值0x03。同样,通过添加,'0'
您可以从一位数字值转换回其对应的字符。
在固定的硬编码值的情况下,这没有多大意义,但是在从终端获取输入的示例中,您只能输入字符并必须转换为实际的数值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句