Nasm STOS指令
STOS指令使用AL(字节 - STOSB),AX(字 - STOSW)或EAX(对于双 - STOSD的)数据复制目标字符串,在内存中通过ES:DI指向。
下面的示例演示使用LODS和STOS指令,其小写值转换为大写字符串:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry bytekits
movecx, len
movesi, s1
movedi, s2
loop_here:
lodsb
or al, 20h
stosb
looploop_here
cld
rep movsb
mov edx,20 ;message length
mov ecx,s2 ;message to write
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
s1 db 'HELLO, WORLD', 0 ;source
len equ $-s1
section .bss
s2 resb 20 ;destination
上面的代码编译和执行时,它会产生以下结果:
hello, world