1

I'm testing out writing text to a screen using emu8086. I'm trying to print out a 3x3 grid with the letters A to I. I imagine this isn't the conventional way to move the cursor down (perform a carriage return) but it should work.

org 100h

;
; Initialise
;
                   
; Set video mode
mov AL, 13h
mov AH, 0
int 10h

; Set cursor position
mov DH, 1
mov DL, 1
mov BH, 0
mov AH, 2
int 10h

; Set cursor intensity/blinking
mov ax, 1003h
mov bx, 0
int 10h

; Set attribute to white foreground, black background
mov BL, 0Fh
    
    
call print_grid
jmp end

print_char PROC
                                                         
    mov AH, 09h ; Set interrupt to print
    mov CX, 1 ; So that the character is only printed once
    
    int 10h
    
    inc DL ; Incrementing the cursor position horizontally
    mov AH, 2h ; Set interrupt to set cursor position
    int 10h
      
    ret
print_char ENDP

carriage_return PROC
    inc DH ; Incrementing the cursor position vertically
    mov DL, 1 ; Resetting horizontal cursor position
    mov AH, 2h ; Set interrupt to set cursor position
    int 10h
    
    ret
    
carriage_return ENDP

; Prints the grid to the screen
print_grid PROC 
    
    ; Row 1
    
    mov AL, pos[0]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[1]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[2]
    call print_char
    
    call carriage_return
    
    ; Row 2
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    call carriage_return
    
    ; Row 3
    
    mov AL, pos[3]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[4]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[5]
    call print_char
    
    call carriage_return
    
    ; Row 4
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    mov AL, '+'
    call print_char
    
    mov AL, '-'
    call print_char
    
    call carriage_return
    
    ; Row 5
    
    mov AL, pos[6]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[7]
    call print_char
    
    mov AL, '|'
    call print_char
    
    mov AL, pos[8]
    call print_char
    
    call carriage_return
    
    ret
print_grid ENDP 

end:

ret

pos DB 65, 66, 67, 68, 69, 70, 71, 72, 73

What appears on the virtual screen is this

I know that there are better methods to print characters using emu8086 such as the PRINT/PRINTN macros but I wanted to try doing it manually, so I would appreciate an answer as to why the program is outputting this. Though general tips on improving this code are welcome, if you'd like.

Hayden
  • 45
  • 6
  • Have you tried single-stepping your code, and watching the values of DH and DL as you go? – Nate Eldredge Oct 16 '21 at 15:37
  • 2
    emu8086 is known for its many bugs and quirks. See if your program runs fine on the normal text screen `mov ax, 0003h` `int 10h`. And perhaps loose the Intensity/Blinking call. I'm not entirely sure that the 256-color screen is even *officially* supported. – Sep Roland Oct 16 '21 at 16:21
  • @NateEldredge Yes, I've tried stepping through the code and DL/DH do not change to any unexpected values – Hayden Oct 16 '21 at 18:09
  • 1
    @SepRoland Ahh, I hadn't even noticed that I had set the screen mode to graphical (wasn't my intention). Changing it to 03h made it work. Thank you – Hayden Oct 16 '21 at 18:11
  • Does this answer your question? [Graphics mode in assembly 8086](https://stackoverflow.com/questions/48648548/graphics-mode-in-assembly-8086) – Peter Cordes Oct 17 '21 at 04:58
  • @PeterCordes Although that question specifically does not solve my question, I did have the output set to the wrong graphics mode. Thanks – Hayden Oct 17 '21 at 22:12
  • Since you apparently didn't even intend to be using a graphical mode, I figured this question should be closed, so I picked a duplicate about setting video mode, since that was the ultimate problem. IDK if the calls you were using are supposed to work in graphics mode and that's just an emu8086 bug; if so it might be interesting to record that. But if they're not expected to work in the first place and that's documented in places like Ralf Brown's interrupt list, then yeah probably just close. – Peter Cordes Oct 17 '21 at 22:19

0 Answers0