1

I am trying to write the letter 'D' in blue on a white background by moving it to the video buffer. What is wrong with this code?

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

Made the changes to above. It now assembles, but displays nothing.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Daniel
  • 6,595
  • 9
  • 38
  • 70
  • You should post what your code *actually* does, not just what you expect. – Gabe Dec 01 '11 at 01:02
  • It does nothing. it will not assemble. – Daniel Dec 01 '11 at 01:02
  • @Daniel: Been ages since I did masm, but did you try the ASCII equivalent as an integer, which is decimal 69? – Eric J. Dec 01 '11 at 01:07
  • 1
    Saying 'it will not assemble' is particularly unhelpful. How about posting the exact error output you're getting? – Gian Dec 01 '11 at 01:09
  • @Gian it now will assemble, but prints nothing. – Daniel Dec 01 '11 at 01:11
  • @EricJ. I have now tried the ASCII equivalent. It now will assemble, but prints nothing. – Daniel Dec 01 '11 at 01:12
  • You've been asked to provide more information (actual code, error messages, etc.), and you just keep post comments saying the same things. If you want help, edit your question to provide the details you've been asked to provide; it's much easier (and faster) that way than it is to play 20 questions in comments. :) – Ken White Dec 01 '11 at 01:15
  • @KenWhite OK I have posted the entirety of my program. It now assembles but does nothing, just sits with a blank console window until a key is pressed. – Daniel Dec 01 '11 at 01:21

3 Answers3

3
  1. 0b800h is the segment address of the video buffer. mov word ptr [si], 44h addresses just the offset (here: 0b800h) of the segment address in DS - and DSdoesn't point to the video buffer. I suggest to load the video segment into ES and to use a segment override (ES:).

  2. Letter plus colors form together a word. In the video buffer first comes the letter then the colors. Background and foreground colors use each a nibble (4 bit). Due to "little endianness" (google for it) a word should have the format colors/letter, e.g. white/blue/'D' = 7144h

This is an Irvine16 compatible example:

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
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
rkhb
  • 14,159
  • 7
  • 32
  • 60
3

Sample example:

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

Hope this sample helps you

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • Yes! Thank you. I'm new to assembly, so I'm making dumb mistakes. – Daniel Dec 01 '11 at 01:34
  • @Sudhir Bastakoti I have data segment as `msg db 10,13,'Enter Sting: $' buffer db 20` and i try to display buffer content but it displays content of `msg` which is `Enter String: `. – Ahtisham Nov 21 '17 at 15:14
0

Have a look at Listing 15 here:

http://stuff.pypt.lt/ggt80x86a/asm8.htm

Eric J.
  • 147,927
  • 63
  • 340
  • 553