在两个不同的行上打印一个字符串 [英] print a string on two different lines

查看:75
本文介绍了在两个不同的行上打印一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的程序在两个不同的行上显示一个字符串.

I am trying to get my program to display a string on two different lines.

这是一个.com程序,我正在使用A86汇编程序.

This is a .com program and I am using A86 assembler.

jmp start               ; This will start the program

;============================

  msg   db  "Hello Word.$"      ; A string variable 
  msg   db  "Michael J. Crawley$"   ; A string variable with a value.

;============================

start:

  mov ah,09             ; subfunction 9 output a string

  mov dx,offset msg         ; DX for the string

  int 21h               ; Output the message

  int 21h               ; Output the message

exit:

  mov ah,4ch
  mov al,00             ; Exit code 

  int 21h               ; End program

推荐答案

以下是您的特定问题:

  • 您两次定义msg(a86会拒绝).
  • 您以msg的 same 值调用int21 fn9,因此您不会打印出两条消息,而只是打印出第一条消息的两个副本.
  • 任何一条消息中都没有换行符,因此它们彼此邻接而不是放在单独的行上.
  • You define msg twice (a86 will barf on that).
  • You call int21 fn9 with the same value of msg so you're not printing the two messages out, just two copies of the first.
  • You don't have a newline character in either message so they'll abut each other rather than be on separate lines.

针对这些问题的解决方案(不提供实际代码).

The solutions to those points (without providing the actual code).

  • 将第二条消息标记为msg2.
  • 在第二次调用int21之前,将msg2加载到dx中.
  • 更改消息以在"$"符号(或至少第一个符号)之前放置换行符.
  • Label the second message as msg2.
  • Load msg2 into dx before calling int21 for the second time.
  • Change the messages to put a newline before the '$' symbol (or at least the first one).

更新:由于其他有用的灵魂已经提供了源代码,因此这是我的解决方案.我建议您学习,并修改自己的代码以执行类似的操作.如果您从公共站点逐字抄袭该文件进行课堂作业,几乎肯定会因抄袭而被抓到

Update: Since some other helpful soul has already provided source, here's my solution. I would suggest you learn from this and modify your own code to do a similar thing. If you copy it verbatim from a public site for classwork, you'll almost certainly be caught out for plagiarism:

         jmp start                   ; This will start the program

msg      db  "Hello Word.",0a,"$"    ; A string variable .
msg2     db  "Michael J. Crawley$"   ; A string variable with a value.

start:   mov ah,09                   ; subfunction 9 output a string
         mov dx,offset msg           ; DX for the string
         int 21h                     ; Output the message
         mov dx,offset msg2          ; DX for the string
         int 21h                     ; Output the message
exit:
         mov ah,4ch
         mov al,00                   ; Exit code 
         int 21h                     ; End program

这将输出:

Hello Word.
Michael J. Crawley

这篇关于在两个不同的行上打印一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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