我正在使用x86程序集,并且使用它,我需要使用20个字符或更多字符串,并从用户获取一个字符。然后我需要将每个字符串旋转两位,然后使用ASCII代码XOR
。
问题是我可以获取用户字符串和char,但是如何循环遍历字符串?我尝试像数组一样循环遍历它,但随后它就崩溃了。
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
WriteDec PROTO
WriteString PROTO
WriteChar PROTO
Crlf PROTO
ReadString PROTO
DumpRegs PROTO
Delay PROTO
.data
MAX = 80 ;max chars to read, if we input more it just gets cut off
stringIn BYTE MAX+1 DUP (?) ;room for null
stringASCII BYTE MAX+1 DUP (?) ;room for null
CharMAX = 2;
storedString DWORD ?
storedASCII DWord ?
savedSpots Dword ?
Command byte "Enter your 20 Word string" ,0
askforChar byte "Enter a char" ,0
Encrypt byte "Encrypted String" ,0
.code
main PROC
mov edx , OFFSET Command ;Enter your 20 word String
call WriteString ;print it
call CRLF ;space
mov edx, OFFSET stringIn ;get the address of where we are gonna put our response
mov ecx, MAX ;mov max value of chars
call ReadString ;read it
call CRLF ;space
mov edx , OFFSET askforChar ;Then ask for a single char
call WriteString ;write it out
call CRLF ;clear the line
mov edx, OFFSET stringASCII ;get the address of where we are gonna put our char
mov ecx, CharMAX ;get the one ASCII code
call ReadString ;double space
call CRLf ;double space
mov edx, OFFSET stringASCII ;this was just a test to reprint our word
mov storedASCII, edx ;
mov ecx, CharMAX ;get the same max value
call CRLF
mov edx , OFFSET Encrypt ;Encrypted String
call WriteString ;print it
call CRLF ;space
mov esi,OFFSET stringIN ;get our string address
mov ecx, MAX ;get our counter
L1:
mov edx, [esi]
call WriteChar
call CRLF
add esi, TYPE stringIN
Loop L1;
ret
main ENDP
end main
编辑:重新添加循环