.data
myString db "Hello",0
.code
mov si,offset myString
mov ax,0
mov cx,0
cld
stringReverse:
lodsb ;read the letter (and inc si to the next letter)
cmp al,0 ;is it zero
jz nowReverse ;if so, reverse the string
push ax ;push the letter onto the stack
inc cx ;increment our counter
jmp stringReverse
nowReverse:
mov si,offset myString ;reload the pointer to the first letter in myString
loop_nowReverse:
jcxz done ;once we've written all the letters, stop.
pop ax ;get the letters back in reverse order
stosb ;overwrite the old string
dec cx
jmp loop_nowReverse
done:
1条答案
按热度按时间xam8gpfp1#
使用
push
可以做很多事情:在8086上,你只能通过1或
CL
寄存器中的值进行位移位或循环移位。如果你使用CX
作为循环计数器,但你试图在循环中进行位移位,这可能会成为一个问题。所以你可以用下面的方法来解决这个问题: