STOS指令使用AL(字節(jié) - STOSB),AX(字 - STOSW)或EAX(對(duì)于雙 - STOSD的)數(shù)據(jù)復(fù)制目標(biāo)字符串,在內(nèi)存中通過(guò)ES:DI指向。
下面的示例演示使用LODS和STOS指令,其小寫值轉(zhuǎn)換為大寫字符串:
section .text global _start ;must be declared for using gcc _start: ;tell linker entry yiibai mov ecx, len mov esi, s1 mov edi, s2 loop_here: lodsb or al, 20h stosb loop loop_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
上面的代碼編譯和執(zhí)行時(shí),它會(huì)產(chǎn)生以下結(jié)果:
hello, world