汇编语言

时间:2010-02-12 04:11:10

标签: assembly

我非常喜欢新秀。我确信这是非常基本的,但我已经多次这样做了。我试图让我的程序在两个不同的行上显示一个字符串。这是一个.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

3 个答案:

答案 0 :(得分:3)

以下是您的具体问题:

  • 您定义msg两次(a86会对此进行barf)。
  • 使用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

答案 1 :(得分:1)

msg的两个定义?

答案 2 :(得分:0)

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