讓我們假設我必須將字符串存儲在.BSS部分中創建的變量中。將字符串從BSS變量複製到程序集中的BSS變量
var1 resw 5 ; this is "abcde" (UNICODE)
var2 resw 5 ; here I will copy the first one
我該如何與NASM做這件事? 我想是這樣的:
mov ebx, var2 ; Here we will copy the string
mov dx, 5 ; Length of the string
mov esi, dword var1 ; The variable to be copied
.Copy:
lodsw
mov [ebx], word ax ; Copy the character into the address from EBX
inc ebx ; Increment the EBX register for the next character to copy
dec dx ; Decrement DX
cmp dx, 0 ; If DX is 0 we reached the end
jg .Copy ; Otherwise copy the next one
所以,第一個問題是,字符串是不可複製的UNICODE但作爲ASCII,我不知道爲什麼。其次,我知道可能有一些不推薦使用某些寄存器。最後,我想知道是否有一些更快的方法來做到這一點(也許有專門爲字符串這種操作創建的說明)。我正在談論8086處理器。
'INC' /'dec' /'cmp'?爲什麼不'rep stos'? –
因爲我不知道它。謝謝 – ali