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

问题描述 投票:2回答:3

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

这是一个.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
assembly dos x86-16 a86
3个回答
3
投票

这是您的特定问题:

  • 您两次定义了msg(a86会否决)。
  • 您使用msg的same值调用int21 fn9,因此您不会打印出两条消息,而只是打印出第一条消息的两个副本。
  • 任何一条消息中都没有换行符,因此它们彼此邻接而不是放在单独的行上。

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

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

  • 更新:

由于其他有用的灵魂已经提供了源,因此这是我的解决方案。我建议您从中learn并修改您自己的代码以执行类似的操作。如果您从公共站点上逐字抄袭以进行课堂作业,几乎肯定会因抄袭而被抓获:
         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

1
投票

味精的两个定义?


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.