【问题标题】:String printing assembly language program not executing in command prompt字符串打印汇编语言程序未在命令提示符下执行
【发布时间】:2013-12-13 17:43:12
【问题描述】:

我正在学习,我是汇编语言编程的初学者,我们目前正在学习字符串打印和操作显示内存。在谈论这个问题之前,我想先介绍一下背景。我们正在为 iapx88(intel 8088)处理器架构制作程序,我们正在使用 nasm 汇编器和 afd 调试器。我使用 32 位 Windows 7 Ultimate。 我的问题是,即使代码在调试器中正确运行,我也无法在命令提示符下执行任何字符串打印程序。所附图像将有助于更好地解释问题。我们的导师告诉我们运行一个全屏的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) 按回车后:(http://i.imgur.com/UWoH0LM.png)

我希望我已经充分解释了我的问题。我试图用谷歌搜索这个问题的解决方案,但我找不到。如果你们能帮助我并告诉我我的代码做错了什么,我将非常感谢你们。 谢谢。

【问题讨论】:

    标签: string assembly cmd dos


    【解决方案1】:

    您正在使用 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. 运行您的程序。有效!

    似乎Windows中包含的DOS VM在执行EXE程序之前不会映射文本屏幕内存。将再次测试您的程序,但转换为 EXE 应用程序,看看我是否正确。


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

    mov ax,3
    int 10h  ;select 80x25 color text mode
    

    【讨论】:

    • 那么它使用的是什么模式呢? +1
    • 令我惊讶的是,报告的是模式 3(通过在 40h:49h 处窥视字节或发出 int 10h,函数 0xF),但 VM 似乎直到明确调用执行 AH=0 的 int 10h。
    猜你喜欢
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    相关资源
    最近更新 更多