Irvine的WriteString产生奇怪的输出 [英] Strange output with Irvine's WriteString

查看:95
本文介绍了Irvine的WriteString产生奇怪的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下程序的要点是打印出带有所有背景色和前景色的字母"c".

the point of the following program is to print out the letter "c" with the combination of every background and foreground color.

在我正在使用的库中,颜色定义为0-15,并使用以下代码:

In the library I'm using the colors are defined 0-15 and with the following code:

mov eax,FOREGROUND + (BACKGROUND * 16) 
call SetTextColor 

这是我的代码:

INCLUDE Irvine32.inc
.data

character BYTE "c"
count DWORD ?
background DWORD 0

.code
main PROC
    call Clrscr

    mov ecx, 15                             ; our main counter 0-15 colors

L1:     
    mov count, ecx                          ; store our outer loop counter
    mov ecx, 15                             ; set out inner loop counter
L2:     
    ; since our color is defined like so... mov eax,FOREGROUND + (BACKGROUND * 16)
    mov eax, count                          ; setup our foreground color
    add eax, background                     ; setup our background color
    call SetTextColor

    ;  instead of multiplying each background color by 16, we are going to 
    ; add 16 each time. 
    add background, 16                      

    ; print the character
    mov edx, OFFSET character
    call WriteString 
    loop L2

    mov ecx, count                          ; reset our outside loop
    loop L1

    call Crlf
    exit
main ENDP

END main

现在,我正在使用Windows 7,上面的代码有效",但是由于某种原因,它到达了某个点,程序停止了,并且计算机开始发出蜂鸣声.另外,在程序的特定位置,它开始打印带有字母c.的随机字符.这是我的输出:

Now, I'm using windows 7, the above code "works" but for some reason, it goes to a certain point, the program stops, and the computer starts beeping. Also, at a certain point in the program, it starts printing random characters with the letter c.. here is my output:

c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♀c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c♂c
c
c
c
c
c
c
c
c
c
c
c
c
c
c
c       c       c       c       c       c       c       c       c       c
c       c       c       c       c       cccccccccccccccc♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c♠c
♠c♠c♠c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♣c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♦c♥c♥c♥c♥c♥c♥c♥c
♥c♥c♥c♥c♥c♥c♥c♥c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☻c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺c☺
Press any key to continue . . .

有人可以告诉我为什么会这样吗?

Can anyone tell me why this is happening?

推荐答案

Irvine的此处(IrvineLibHelp.exe)中下载该帮助.

Irvine's WriteString needs a "null-terminated string". Some can download the help as CHM-file here (IrvineLibHelp.exe).

说"EDX =指向字符串"有点草率. EDX只是指向可通过标签标识的内存地址(此处为字符"). WriteString将从该位置逐字节获取字节,并将其写为字符或控制指令,无论其实际类型或意图如何,直到遇到值0的字节为止.MASM没有指令定义最后一个0的字符串,因此必须手动添加:

It's a little bit sloppy to say "EDX = points to string". EDX just points to an memory address identifiable by a label (here: "character"). WriteString will get byte for byte from that location and write it as character or control directive regardless of his real type or intention until it comes across a byte with the value 0. MASM has no directive to define a string with the last 0, so it has to be added manually:

character BYTE "c", 0

打印字符的另一种方法是使用

An alternative way to print a character is to use WriteChar:

...
; print the character
mov al, character
call WriteChar
loop L2

mov ecx, count                          ; reset our outside loop
loop L1
...

这篇关于Irvine的WriteString产生奇怪的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆