无法在8086反转字符串MASM [英] Unable to reverse string in 8086 MASM

查看:310
本文介绍了无法在8086反转字符串MASM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一些8086汇编code扭转的字符串。我是比较新的组装所以请多多包涵。

I've written some 8086 assembly code to reverse a string. I'm relatively new to assembly so please bear with me.

的逻辑是,我定义了一个名为STR1字符串。我搬进的 SI 的注册此。假设字符串'STR1'是的你好$的,然后我'STR1'+ 5的地址载入的 SI 的。现在,我加载一个地址,说成5000的 DI 的。而从我的 SI 的加载每个字符放入的 DI 的,每次我SI递增和递减至SI 5次。

The logic is that I define a string called 'str1'. I move this into the SI Register. Suppose string 'str1' is "Hello$", then I load the address of 'str1'+5 into SI. Now, I load an address, say 5000 into DI. And I load each character from SI into DI and everytime I increment SI and decrement SI till 5 times.

下面是code

assume cs:code,ds:data
data segment
str db "Hello$"
data ends
code segment
start:
mov ax,data
mov ds,ax
cld
mov cx,5h
mov bx,5h
lea si,str
add si,5
mov di,5000h
l1:mov bx,[si]
mov [di],bx
dec si
inc di
loop l1
hlt
code ends
end


我得到一个绝对的垃圾值,当我访问位置5000 plz帮助的感谢


I get an absolute garbage value when I access location 5000. Plz help thanks

推荐答案

您code是差不多好了,你只需要一个辅助字符串(如果这样的事情是允许的):

Your code is almost good, you only need an auxiliary string (if such thing is allowed) :

assume cs:code,ds:data
data segment
str db "Hello$"
aux db "     $"       ;AUXILIARY STRING.
data ends
code segment
start:
mov ax,data
mov ds,ax
cld
mov cx,5h
mov bx,5h
lea si,str
add si,4              ;0..4 = 5.
lea di,aux            ;POINT TO AUXILIARY.
l1:mov bl,[si]        ;YEAH, LET'S USE
mov [di],bl           ;"BL" INSTEAD OF "BX".
dec si
inc di
loop l1
hlt
code ends
end

这篇关于无法在8086反转字符串MASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆