【发布时间】:2021-12-28 21:10:37
【问题描述】:
我正在努力学习 nasm, 按照this教程,我写了这段代码
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 的输出是一个奇怪的字符 �%,它必须打印 'z'
我错过了什么吗?
【问题讨论】:
-
add al, byte '0'你的角色'z'是 ascii.