Reputation: 115
Basically, I have to "paint" a simple picture of a house in my DOS Box using assembly code. Part of this picture involves a sky in the background and a green patch of grass underneath. I was told I can accomplish this by any method I wanted, but I was never taught much about x86 graphics mode. So, I decided to accomplish the goal in mode 3 (80x25 text mode). Basically, I am using loop structures to print empty spaces with highlights.
I've managed to paint the sky (along with several unintentional randomly assorted letters on the screen). However, my next instruction is to move the cursor to a certain position to the screen and then print the grass portion, but this does not happen. I'm not sure if NASM is simply ignoring the instruction, if it has no way to get to it, or if my code is wrong. Any insight would be appreciated.
Here is my code:
org 100h
section .text
mov ah, 0 ;change to 80x25 color text mode
mov al, 3
int 10h
drawSky:
mov ax, 0b800h ;color activate display page
mov ds, ax
mov cx, 2000 ;80x25 = 2000 words
mov di, 0
mov ax, 3320h ;blank spaces with blue background
call fillbuf
drawGrass:
mov ah, 2 ;move cursor
xor bh, bh ;page number 0
mov dh, 14h ;move to row 20
mov dl, 0h ;move to column 0
int 10h
mov ax, 0b800h ;color activate display page
mov ds, ax
mov cx, 1000
mov di, 0
mov ax, 2220h ;blank spaces with blue background
call fillbuf
fillbuf:
mov [di], ax ;character in al, attribute in ah
add di, 2 ;go to next word
loop fillbuf
Upvotes: 3
Views: 913
Reputation: 61989
fillbuf
needs to end with a ret
instruction.
What is happening now is that you are invoking fillbuf
, it displays the first text, and then it proceeds to execute random bytes past the end of your program, which is basically a crash. It never returns, so nothing else is printed.
The random bytes are interpreted as instructions, and since ds: already points to the video ram, the video ram receives some random garbage, thus the cute "unintentional randomly assorted letters" that you see. Just keep in mind for the future, that when you see those, you have a crash.
Also, since your program crashes, you are most probably receiving some kind of error, which you have not told us anything about. When asking questions on stackoverflow, please make it a point to mention any error messages that you might be seeing, they tend to be a bit pertinent.
Also, since you are directly accessing the video ram, you have no use for the cursor. You would have needed to place the cursor at a certain position if you were to use some other interrupt which emits text at the cursor location. But you are not doing that, so the cursor is of no use to you. If your instructor requires you to use the cursor, then he is also expecting you to use some interrupt instead of directly accessing the video ram.
Upvotes: 2