如何扭转在汇编语言的字符串? [英] How to reverse a string in assembly language?

查看:207
本文介绍了如何扭转在汇编语言的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习汇编语言的,我要打印的Hello World以相反的顺序,这意味着dlrow东海生日贺。问题是我得到只有第一个字母为输出,令仍然一样没有变化在所有!作为一个新手,很多东西是未知的,我和我在做很多错误,我无法确定他们由于缺乏knowledge.So的适当解释任何回答将是AP preciated!这里是我的code:

 名为喜;有谁能够解释什么用的呢?组织100HJMP启动;跳过数据声明味精DB1Hello,世界!,0;最后一个字符
MSG1 DB1MOV SI,13;字符串的lenght
开始:MOV AL,味精[SI]
DEC SIMOV啊,0EH
INT 10H
MOV BL,MSG1CMP味精[SI],BL;比较,以获得弦的端部
JE停止JMP启动停止:
MOV啊,0
INT 16H;等待任何关键....
RET;返回到操作系统。

我得到的输出只有1,这是首个字母,但我希望得到相反的顺序整个字符串


解决方案

  JMP启动;跳过数据declaratio
...
MOV SI,13;字符串的lenght
开始:

现在的问题是 - 你没有初始化寄存器 SI

您需要使用这样的:

  JMP初始化;跳过数据declaratio
...
在里面:
MOV SI,13;字符串的lenght
开始:

I have just started to learn assembly language and i am trying to print "hello world" in reverse order that means "dlrow olleh".the problem is i am getting only 1st letter as output and the order is still same no change at all!As a newbie many thing is unknown to me and i am doing lots of mistakes and i am unable to identify them due to lack of knowledge.So any answer with proper explanation will be appreciated!Here is my code:

name "hi" ; can anybody explain what is the use of this?

org 100h

jmp start       ; jump over data declaration

msg    db      "1Hello, World!",0;last character           
msg1   db      "1"

Mov   SI,13;lenght of the string
start: 

Mov  AL,msg[SI]
DEC SI 

Mov  ah ,0eh
int 10h   
mov BL,msg1

CMP msg[SI],BL;comparing to get the end of the string
je stop

jmp start                     

stop:
mov     ah, 0 
int     16h      ; wait for any key....
ret ; return to operating system.

i am getting output only "1" which is the first letter,but i expected to get the whole string in reverse order

解决方案

jmp start       ; jump over data declaratio
...
Mov   SI,13;lenght of the string
start: 

here is the problem - you're not initializing register si

you need to use something like:

jmp init       ; jump over data declaratio
...
init:
Mov   SI,13;lenght of the string
start: 

这篇关于如何扭转在汇编语言的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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