我的代码打印出垃圾而不是所需的文本

时间:2016-08-03 15:40:42

标签: assembly dos dosbox vga x86-16

我使用16位程序集来创建一个DOS程序,用于教育目的如何编程VGA,我编写了一个代码来为某些像素写入颜色打印一个字符串,代码改变了像素颜色,但是当我尝试打印字符串时,它会打印奇怪的字符,分配它们 我使用MASM 5.00和Link 3.60并在DOSBox上运行

这是我的代码

org 100h
.model small
.stack 100h
.data
msg         db      'Hello VGA','$'
.code
main proc
mov ax, 0                                
mov al, 013h                             
int 10h

mov ah, 02h                                  ;function code for setting cursor pos.
mov bh, 0                                    ;setting page number
mov dx, 0                                    ;setting dh, dl to row and column
int 10h

mov ah, 0ch                                 
mov al, 00001110b                    
mov cx, -1

ploop:
inc cx                                           ;x point pos.
mov dx, 0                                  ;y point pos.
int 10h
cmp cx, 9919
jne ploop
;keyboard services

mov ah, 00h                                 ;read key function code
int 16h             

;set cursor position
mov ah, 02h
mov bh, 0                                       ;Display page
mov dh, 04h                                 ;Row
mov dl, 00h                                 ;Column
int 10h

;print msg
mov ah, 09h
lea dx, msg
int 21h
mov ax, 4c00h
int 21h
main endp
        end main

1 个答案:

答案 0 :(得分:1)

我刚刚运行了你的代码,它对我很好。尝试手动初始化数据段,在.code之后立即插入下两行:

.code
  mov ax, @data
  mov ds, ax
  .
  .
  .