在两个不同的行上打印一个字符串

发布于 2024-08-21 00:03:20 字数 636 浏览 4 评论 0原文

我试图让我的程序在两个不同的行上显示一个字符串。

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筱果果 2024-08-28 00:03:20

以下是您的具体问题:

  • 您定义了两次 msg (a86 会对此感到厌烦)。
  • 您使用 msg 的相同值调用 int21 fn9,这样您就不会打印出两条消息,而只是打印出第一条消息的两个副本。
  • 两条消息中都没有换行符,因此它们会彼此相邻,而不是位于不同的行上。

这些点的解决方案(不提供实际代码)。

  • 将第二条消息标记为 msg2
  • 在第二次调用 int21 之前将 msg2 加载到 dx 中。
  • 更改消息以在“$”符号(或至少第一个符号)之前添加换行符。

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

         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

Here are your specific problems:

  • 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).

  • 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

This outputs:

Hello Word.
Michael J. Crawley
岁吢 2024-08-28 00:03:20

msg 的两种定义?

Two definitions of msg?

娇女薄笑 2024-08-28 00:03:20

我不熟悉 a86,但熟悉 NASM 和 NASM。 MASM 在 com 程序的开头需要一个“org 100h”汇编指令。现在的情况是,offset msg 是 0x2,它将尝试从程序段前缀的第二个字节(一个 16 位字,保存可用内存顶部的段)开始打印。

I'm not familiar with a86, but with NASM & MASM you need an "org 100h" assembler directive at the beginning of a com program. The way it is now, offset msg is 0x2, and that'll try to print from the second byte of the program segment prefix (a 16 bit word that holds the segment of the top of memory available to you).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文