反向时出现故障并在组装中显示字符串 [英] Trouble when reverse and display string in assembly

查看:88
本文介绍了反向时出现故障并在组装中显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

model small
stack 100h

.data
string1 db "Khoa$"
string2 db 4 dup(?)
count dw 4
.code
begin:  
mov ax,@data
mov ds,ax
mov es,ax
mov cx,count
mov si,0
mov di,0
add di,count
dec di

again:  mov al,string1[si]
mov string2[di],al
inc si
dec di
loop again

mov ah,9
lea dx,string1
int 21h

end begin

在这部分

mov ah,9
lea dx,string1
int 21h

当我尝试显示string1进行控制台时,没关系. 但是string2没有结果.

when i try to display string1 to console, it's ok. but no result with string2.

我是组装的新手.请帮忙!

i'm new to assembly. Please help!

推荐答案

尽管这是家庭作业,但这是解决问题的合理尝试.我不知道您使用的是什么汇编程序-看起来像 MASM ,但我不确定这两行如何进行汇编而不会出现语法错误:

Although this is homework, this is a reasonable attempt at a solution. I don't know what assembler you are using - it looks like MASM but I'm unsure how these 2 lines could assemble without a syntax error:

model small
stack 100h

我认为这应该是(请注意前面的期间,因为它们是汇编器指令):

I think this should be (note the periods in front as they are assembler directives):

.model small
.stack 100h

string1最初为5个字符长,包括$以终止字符串.使用 int 21h/ah 9 时,字符串必须用$终止,否则它将继续在字符串末尾打印垃圾.考虑到这一点,您的输出缓冲区应该足够长以容纳5个字符,包括$ 所以string2应该定义为:

string1 is initially 5 characters long including the $ to terminate the string. When using int 21h/ah 9 strings need to be terminated with $ or it will continue to print junk beyond the end of your string. With that in mind your output buffer should be long enough to hold 5 characters including the $ so string2 should be defined as:

string2 db 5 dup(?)

代码中的主要问题是用$终止字符串.一种方法是在最初设置sidi寄存器时将$放置在数组的最后一个位置:

The primary problem in your code is terminating the string with a $. One way would be to place the $ in the last position of the array when you set up the si and di registers initially:

mov si,0
mov di,0
add di,count
mov string2[di],'$'   ; Put string terminator in last position
dec di

还请注意:

mov di,0
add di,count

可以简单地写为:

mov di, count

如果您正在使用 MASM ,要正常退出您的16位程序,您可能希望在end语句之前放置一个.exit指令:

If you are using MASM, to gracefully exit your 16 bit program you might want to put a .exit directive just before your end statement:

.exit
end begin

这篇关于反向时出现故障并在组装中显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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