저는 Assembly (그리고 일반적으로 솔직히 프로그래밍)에 익숙하지 않습니다. 나는 스택을 가지고 노는 중이 야. 이 코드의 목적 : 제한된 문자열에서이어셈블리 - 문자열을 뒤집어 쓰려고하지만 최종 문자열에 여분의 문자가 추가됩니다.
- 테이크, 80 자
- 재 인쇄가 스택
- 인쇄 각에 밀려으로
- 인쇄 각 문자를 입력 한 문자열 스택에서 튀어 나오는 문자
- 역순 문자열을 인쇄하십시오.
코드가 마지막 단계에서 실패합니다.
입력 한 문자열이 "도움말"이면 "pleHe"가 인쇄됩니다. 마지막 String의 마지막 문자는 원래 String의 두 번째 문자입니다.
내가 어수선한 곳을 볼 수 있도록 도와주세요!
.data buffer WORD 81 DUP(0) byteCount WORD ? .code main PROC call Clrscr ;Clear screen RS: mov edx, OFFSET buffer ;Move String to edx mov cl, [SIZEOF buffer]-1 ;Set loop counter to (size of buffer) -1 call ReadString ;Read a User's String mov byteCount, ax ;Move the size of User's String to byteCount cmp byteCount, 80 ;Compare byteCount with 80 ja RS ;If byteCount is greater then 80, ask for another String call WriteString ;Write User's String to screen call Crlf ;New Line call reverseIt ;Reverse order of String exit reverseIt PROC movzx ecx, byteCount ;Set Loop1 Counter to size of String mov esi, 0 ;Zero out ESI L1: ;Loop1 - Pushes String into Stack one character at a time movzx eax, buffer[esi] ;Dereference buffer and place in eax call Crlf ;New Line call WriteChar ;Print current character to screen push eax ;Push current character to stack inc esi ;Move to next character loop L1 call Crlf movzx ecx, byteCount ;Set Loop2 Counter to size of String mov esi, 0 ;Zero out ESI L2: ;Loop2 - Pops Characters back into String in reverse order pop eax ;Retrieve character from top of stack call Crlf ;New Line call WriteChar ;Print current character to screen mov buffer[esi], ax ;Writes character to String inc esi ;Increase esi loop L2 call Crlf ;New Line call Crlf ;New Line mov edx, OFFSET buffer ;Move String to edx for WriteString call WriteString ;Prints String to Screen call Crlf ;New Line ret ;Return to main reverseIt ENDP main ENDP END main
디스어셈블러를 통해 단계별 처리하십시오. 두 번째 "e"가 버퍼에 추가되는 위치를 찾아보십시오. –