2011-12-01 61 views
1

我试图通过将字母'D'移动到视频缓冲区,将它写在白色背景上的蓝色。这段代码有什么问题?将字符写入视频缓冲区MASM

 
INCLUDE Irvine16.inc 

.code 
main PROC 

mov ax,@data 
mov ds,ax 

mov si, 0b800h 
mov word ptr [si], 44h 
mov word ptr [si+2] 0701h 

mov ah, 08h 
int 21h 

exit 

main ENDP 

对上述内容进行了更改。它现在汇编,但什么也没有显示。

+0

你应该张贴你的代码* *其实呢,不是您所期望什么。 – Gabe

+0

它什么也没做。它不会组装。 – Daniel

+0

@Daniel:自从我做了masm之后,我的年龄已经过去了,但是您是否将ASCII码当作整数使用,即十进制69? –

回答

1

样品例如:

 
name "hello-world" 
org 100h 

; set video mode  
mov ax, 3  ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3) 
int 10h  ; do it! 

; cancel blinking and enable all 16 colors: 
mov ax, 1003h 
mov bx, 0 
int 10h 


; set segment register: 
mov  ax, 0b800h 
mov  ds, ax 

; print "hello world" 
; first byte is ascii code, second byte is color code. 

mov [02h], 'h' 

mov [04h], 'e' 

mov [06h], 'l' 

mov [08h], 'l' 

mov [0ah], 'o' 

mov [0ch], ',' 

mov [0eh], 'w' 

mov [10h], 'o' 

mov [12h], 'r' 

mov [14h], 'l' 

mov [16h], 'd' 

mov [18h], '!' 




; color all characters: 
mov cx, 12 ; number of characters. 
mov di, 03h ; start from byte after 'h' 

c: mov [di], 11101100b ; light red(1100) on yellow(1110) 
    add di, 2 ; skip over next ascii code in vga memory. 
    loop c 

; wait for any key press: 
mov ah, 0 
int 16h 

ret 

希望此试验可以帮助你

+0

是的!谢谢。我是装配新手,所以我犯了愚蠢的错误。 – Daniel

+0

@Sudhir Bastakoti我有数据段为'msg db 10,13',输入Sting:$'buffer db 20',我尝试显示缓冲区内容,但是显示'输入字符串:msg'的内容。 – Ahtisham

2

1)0b800h是的地址视频缓冲区。 mov word ptr [si], 44h地址只是偏移量(这里:0b800h)的段地址在DS - 和DS不指向视频缓冲区。我建议将视频片段加载到ES并使用片段覆盖(ES:)。

2)字母加颜色形成一个单词。在视频缓冲区中首先出现字母,然后是颜色。背景和前景色使用每个半字节(4位)。由于“little endianness”(谷歌为它)一个单词应该有格式的颜色/字母,例如白/蓝/ 'd'= 7144H

这是一个Irvine16兼容例如:

INCLUDE Irvine16.inc 
INCLUDELIB Irvine16.lib 

.CODE 
main PROC 
; mov ax,@data    ; No .DATA in this example 
; mov ds,ax 

    mov si, 0b800h    ; Initialize ES with video buffer 
    mov es, si 

    xor si, si     ; Position 0 is top left 
    mov word ptr es:[si], 7144h ; White background ('7'), blue foreground (1), letter 'D' (44) 

    mov ah, 08h     ; Wait for key - http://www.ctyme.com/intr/rb-2561.htm 
    int 21h 

    exit      ; Irvine16: end of program 
main ENDP 

END main