[英]or instruction in nasm
我正在尝试学习 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
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
是一个奇怪的字符 �%
它必须打印 'z' 我错过了什么吗?
如果评论or al, bl; 0101 1010 ==> 'Z'
or al, bl; 0101 1010 ==> 'Z'
已经说这是一个字符,那么不清楚你为什么还要向它添加一些东西。
您的添加add al, byte '0'
将48添加到 'Z' 的 ASCII 代码中:
0101 1010 90 'Z'
+ 0011 0000 +48 '0'
---------
1000 1010 138 'è' in codepage 437
仅需要添加byte '0'
才能将 0 到 9 范围内的值转换为“0”到“9”范围内的字符。
它必须打印'z'
要将大写 '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.