[英]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.