嗨,我用80x86汇编语言编写了一个程序,使用连接两个字符串的masm。我要做的是找出第一个字符串的末尾在哪里,然后将第二个字符串的内容添加到第一个字符串中。下面是我到目前为止掌握的代码:
.586
.MODEL FLAT
.STACK 4096
INCLUDE io.h
.DATA
prompt BYTE "Input String", 0
string1 BYTE 80 DUP (?)
string2 BYTE 80 DUP (?)
displayLbl BYTE "Concatenated string", 0
.CODE
_MainProc PROC
input prompt, string1, 80 ; ask for first string
input prompt, string2, 80 ; repeat for second string
lea eax, string1
push eax
lea ebx, string2
push ebx
call strConcatenation ; procedure to concatenate the strings
add esp, 8 ; remove parameters
output displayLbl, string1 ; display result
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
strConcatenation PROC
push ebp
mov ebp, esp
push edi
push esi
pushfd
mov edi, [ebp+8]
repnz scasb ; scan for null in string1
mov esi, [ebp+12]
dec edi
cld
whileConcStr:
cmp BYTE PTR [esi], 0 ; null source byte?
je endWhile ; stop copying if null
lodsb ; load data
stosb ; store data
jmp whileConcStr ; go check next byte
endWhile:
mov BYTE PTR [edi], 0 ; terminate destination string
popfd ; restore flags
pop esi ; restore registers
pop edi
pop ebp
ret
strConcatenation ENDP
END当我输入像‘程序集’和‘语言’这样的字符串时,没有什么变化。任何帮助都是非常感谢的,谢谢。
发布于 2020-11-23 05:32:16
三只虫子:
,
strConcatenation的论点被颠倒了。目前,您正在将string2.的末尾连接到string1。
repne scasb扫描未初始化的al寄存器中的值。若要扫描nul,请将其为零:xor al, al.repne scasb在找到al中的字节时终止,或者当ecx达到零时终止(在每次迭代中都会减少)。您也没有初始化ecx。要无限期地扫描直到找到字节,可以将-1.设置为ecx。
https://stackoverflow.com/questions/64962617
复制相似问题