-1
;This program reverses a string.
INCLUDE Irvine32.inc
.data
   aName BYTE "Abraham Lincoln",0
   nameSize = ($ - aName) - 1
.code

main PROC
   ; Push the name on the stack.
   mov ecx,nameSize
   mov esi,0
   L1: movzx eax,aName[esi] ; get character
     push eax ; push on stack
     inc esi
   Loop L1
   ; Pop the name from the stack, in reverse,
   ; and store in the aName array.
   mov ecx,nameSize
   mov esi,0
   L2: pop eax ; get character
     mov aName[esi],al ; store in string
     inc esi
   Loop L2
   ; Display the name.
   mov edx,OFFSET aName
   call Writestring
   call Crlf
   exit
   main ENDP
END main

我完成了问题的第一部分,即制作一个反向字符串程序,但现在我需要修改程序,以便用户可以输入一个包含 1 到 50 个字符的字符串。我不确定如何做到这一点,并想知道是否有人可以帮忙。这是在汇编语言顺便说一句

4

1 回答 1

2

您可以使用ReadString来自irvine32.lib. 因此,您必须更改nameSize为变量并增加aName.

我为你做的;-):

;This program reverses a string.
INCLUDE Irvine32.inc
.data
   aName BYTE 51 DUP (?)
   nameSize dd ?
.code

main PROC

   mov  edx, OFFSET aName
   mov  ecx, 50            ;buffer size - 1
   call ReadString
   mov nameSize, eax

   ; Push the name on the stack.
   mov ecx,nameSize
   mov esi,0
   L1: movzx eax,aName[esi] ; get character
     push eax ; push on stack
     inc esi
   Loop L1
   ; Pop the name from the stack, in reverse,
   ; and store in the aName array.
   mov ecx,nameSize
   mov esi,0
   L2: pop eax ; get character
     mov aName[esi],al ; store in string
     inc esi
   Loop L2
   ; Display the name.
   mov edx,OFFSET aName
   call Writestring
   call Crlf
   exit
   main ENDP
END main
于 2014-11-10T21:12:21.113 回答