字符串打印程序集语言程序未在命令提示符下执行

时间:2013-12-13 17:43:12

标签: string assembly cmd dos

我正在学习,我是汇编语言编程的初学者,我们目前正在学习字符串打印和操作显示内存。在谈论这个问题之前,我想先介绍一下背景。我们正在为iapx88(intel 8088)处理器架构制作程序,我们正在使用nasm汇编器和afd调试器。我使用的是32位Windows 7旗舰版。 我的问题是我无法在命令提示符中执行任何字符串打印程序,即使代码在调试器中正确运行。附加的图像将有助于更好地解释问题。我们的讲师告诉我们在Dos中执行程序之前运行全屏dos程序(如编辑器)或在afd中运行程序的.com文件。这些提示都没有帮助我。这是我们编写的字符串打印程序之一:

    ; program in assembly to display 'hello world' on screen
    [org 0x0100]
                     push cs
                     pop  ds
                     jmp  start

    message:         db   'hello world'      ; string to be printed
    length:          dw   11                 ; length of the string

   ; subroutine to clear the screen
   clrscr:         push es
                   push ax
                   push di

                   mov  ax, 0xb800
                   mov  es, ax             ; point es to video base
                   mov  di, 0              ; point di to top left column

   nextloc:        mov  word [es:di], 0x0720  ; clear next char on screen
                   add  di, 2              ; move to next screen location
                   cmp  di, 4000           ; has the whole screen cleared
                   jne  nextloc            ; if no clear next position

                   pop  di
                   pop  ax
                   pop  es
                   ret

    ; subroutine to print a string at top left of screen
    ; takes address of string and its length as parameters
    printstr:      push bp
                   mov  bp, sp
                   push es
                   push ax
                   push cx
                   push si
                   push di

                   mov  ax, 0xb800
                   mov  es, ax             ; point es to video base
                   mov  di, 0              ; point di to top left column
                   mov  si, [bp+6]         ; point si to string
                   mov  cx, [bp+4]         ; load length of string in cx
                   mov  ah, 0x07           ; normal attribute fixed in al

    nextchar:      mov  al, [si]           ; load next char of string
                   mov  [es:di], ax        ; show this char on screen
                   add  di, 2              ; move to next screen location
                   add  si, 1              ; move to next char in string
                   loop nextchar           ; repeat the operation cx times


                   pop  di
                   pop  si
                   pop  cx
                   pop  ax
                   pop  es
                   pop  bp
                   ret  4

    start:         call clrscr             ; call the subroutine

                   mov  ax, message
                   push ax                 ; push address of message
                   push word [length]      ; push message length
                   call printstr           ; call the printsr subroutine

                   mov  ax, 0x4c00         ; terminate program
                   int  0x21

这就是我们被告知如何制作该程序的.com文件:

  

nasm hello.asm -o hello.com -l hello.lst

我将所有程序文件与我的D:驱动器中的nasm汇编程序保存在同一文件夹“Assembly”中。这是当我尝试在CMD中执行程序时会发生什么: 首先,我输入程序的名称:(http://i.imgur.com/rTWUxrJ.png) 按“Enter”后:(http://i.imgur.com/UWoH0LM.png

我希望我已经很好地解释了我的问题。我试图谷歌解决这个问题,但我找不到一个。如果你们能帮助我并告诉我我的代码出错了,我会非常感谢你。 感谢。

1 个答案:

答案 0 :(得分:2)

您正在使用Windows来执行DOS程序。这可能会或可能不会工作(如果您使用的是64位版本的Windows,则不会)。我建议你先运行COMMAND.COM,然后从中运行你的程序。


更新:我刚刚尝试过,但它没有用。做了以下工作:

  1. 运行COMMAND.COM
  2. 执行DEBUG程序(古老的DOS调试器)
  3. 在DEBUG提示符下,发出命令db800:0
  4. 显示文本屏幕内存的十六进制转储:大量20 07 20 07 字节
  5. 发出“q”命令退出DEBUG
  6. 在COMMAND.COM提示符下,发出CLS
  7. 运行您的程序。它有效!
  8. 似乎Windows中包含的DOS VM在执行EXE程序之前不会映射文本屏幕内存。将再次测试您的程序,但转换为EXE应用程序,看看我是否正确。


    UPDATE2:忘记EXE / COM问题。这并不是说。这只是DOS VM无法以文本模式3启动,这就是您正在使用的模式。要切换到文本颜色模式,请在调用clrscr以下代码之前在程序开头添加:

    mov ax,3
    int 10h  ;select 80x25 color text mode
    
相关问题