[英]or instruction in nasm
I'm trying to learn nasm, following this tutorial, I have written this code我正在尝试学习 nasm,按照本教程,我已经编写了这段代码
section .text
global _start
_start:
mov al, 1ah ; 0001 1010
mov bl, 40h ; 0100 0000
or al, bl ; 0101 1010 ==> 'Z'
add al, byte '0' ; convert from decimal to ascii
mov [result], al
mov eax, 4 ;syscall (write)
mov ebx, 1 ;file descirptor
mov ecx, result ;message to write
mov edx, 1 ;message length
int 0x80 ;call kernell
jmp outprog
outprog:
mov eax, 1
int 0x80
segment .bss
result resb 1
the output of nasm -f elf hello.asm; ld -m elf_i386 -s -o hello hello.o; ./hello
nasm -f elf hello.asm; ld -m elf_i386 -s -o hello hello.o; ./hello
nasm -f elf hello.asm; ld -m elf_i386 -s -o hello hello.o; ./hello
nasm -f elf hello.asm; ld -m elf_i386 -s -o hello hello.o; ./hello
is a weird character �%
where it had to print 'z' am I missing soemthing? nasm -f elf hello.asm; ld -m elf_i386 -s -o hello hello.o; ./hello
是一个奇怪的字符 �%
它必须打印 'z' 我错过了什么吗?
If the comment on or al, bl; 0101 1010 ==> 'Z'
如果评论
or al, bl; 0101 1010 ==> 'Z'
or al, bl; 0101 1010 ==> 'Z'
already says that this is a character, then it's not clear why you still add something to it. or al, bl; 0101 1010 ==> 'Z'
已经说这是一个字符,那么不清楚你为什么还要向它添加一些东西。
Your addition add al, byte '0'
adds 48 to the ASCII code for 'Z':您的添加
add al, byte '0'
将48添加到 'Z' 的 ASCII 代码中:
0101 1010 90 'Z'
+ 0011 0000 +48 '0'
---------
1000 1010 138 'è' in codepage 437
The addition of byte '0'
is only needed to convert values in the range 0 to 9 into characters in the range "0" to "9".仅需要添加
byte '0'
才能将 0 到 9 范围内的值转换为“0”到“9”范围内的字符。
it had to print 'z'
它必须打印'z'
To convert the uppercase 'Z' into the lowercase 'z' that you seem to expect, the addition would need to be + 32 .要将大写 'Z' 转换为您似乎期望的小写 'z',加法需要为 + 32 。
mov al, 1ah ; 0001 1010
mov bl, 40h ; 0100 0000
or al, bl ; 0101 1010 ==> 'Z'
add al, 32 ; 0111 1010 ==> 'z'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.