【发布时间】: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)
我希望我已经充分解释了我的问题。我试图用谷歌搜索这个问题的解决方案,但我找不到。如果你们能帮助我并告诉我我的代码做错了什么,我将非常感谢你们。 谢谢。
【问题讨论】: