assemblyx86-16masm

MASM Using ah=02h int 21h, display text, highlight with flickering + inverse display


As i understand. Program must clean background, display message1 ( dark letters on white background + highlighting by flickering). then go up for 2 strings and display message2(also dark letters on white background + highlighting by flickering). then go up for 2 strings and display message3(also dark letters on white background + highlighting by flickering). And it says that i need to use 02h function(but didn't says that i cant use other)

It's original task

I tried to start from display message 1 with dark letters on white background + highlighting by flickering.

stack   segment para stack 'stack'  ; start of stack
    db 64 dup('stack***')            
stack   ends                        
 
dseg    segment para public 'data'  ; start of data
    message1 db 'This is line 1:$'
    message2 db 'This is line 2'
    message3 db 'This is line 3'  
    Cls             db      1Bh, '[2J', '$'
    cl1  db  '7m'
dseg ends                           
 
cseg    segment para public 'code'  ;start of commands
prog proc far                      
    assume cs:cseg, ds:dseg, ss:stack 
    
    mov ax, dseg                   
    mov ds, ax                       
    mov  ax,1003h
    mov  bl,112
    int 10h
    
    lea dx,message1
    mov ah, 09h
    int 21h
 
    ;end of program
    mov ah, 4Ch                  
    int 21h                       
prog  endp ; конец процедуры
cseg  ends ; конец сегмента команд
         end prog ; конец программы

Solution

  • [EDIT 8 jan 2025] Following an OP comment, I have added a MASM version of the program.


    The task states to use the DOS.PrintCharacter function 02h. Do note that DOS does not care about colors at all! You will have to use some BIOS function(s) to make the texts colorful and/or blinking.

    On the text video screen a character can be represented in one of 16 foreground colors, and in one of 8 background colors. This accounts for 7 bits in the so-called attribute byte. The remaining 8th bit is dedicated to the blinking aspect: If that particular bit is set, then the character will blink. (This is the default mode of operating after a video mode set, but using that 1003h BIOS function we can choose to abandon the blinking capability in favor of an additional 8 background colors).

    To 'clean the background' my demo program uses the 0600h BIOS function that fills the entire screen with space characters (ASCII 32) using the attribute byte that the user provides in the BH register.

    The attribute byte for BlinkingBlackOnWhite is F0h = 11110000b

    7 6 5 4 3 2 1 0
    ---------------
    . . . . 0 0 0 0  <= Black foreground
    . 1 1 1 . . . .  <= White background
    1 . . . . . . .  <= Blinking aspect
    

    Since the task dictates a certain order for displaying the messages (going up on the screen for which there's no special control code), I used the BIOS.SetCursorPosition function 02h.

    Next is a .COM executable program. I have tested this FASM version in the DOSBox environment and it works allright:

    ; FASM/DOSBox version
    
        ORG   256
    
        mov   ax, 0003h     ; BIOS.SetVideoMode 80x25 16-color text
        int   10h
        mov   dx, 184Fh     ; LowerRightCorner (79,24)
        xor   cx, cx        ; UpperLeftCorner (0,0)
        mov   bh, 0F0h      ; Attribute for blinking BlackOnWhite
        mov   ax, 0600h     ; BIOS.ClearWindow
        int   10h
        mov   si, msg
        call  PrintAT       ; -> SI
        call  PrintAT       ; -> SI
        call  PrintAT       ; -> SI
    
        mov   ah, 00h       ; BIOS.WaitKeystroke
        int   16h           ; -> AX
        mov   ax, 0003h     ; BIOS.SetVideoMode 80x25 16-color text
        int   10h
        mov   ax, 4C00h     ; DOS.TerminateWithReturncode
        int   21h
    ; ----------------------
    ; IN (si) OUT (si)
    PrintAT:
        push  ax
        push  bx
        push  dx
        lodsw
        mov   dx, ax        ; DH is Row, DL is Column
        mov   bh, 0         ; DisplayPage
        mov   ah, 02h       ; BIOS.SetCursorPosition
        int   10h
    
        jmp   .b
    .a: mov   dl, al
        mov   ah, 02h       ; DOS.PrintCharacter
        int   21h           ; -> AL
    .b: lodsb
        cmp   al, 0
        jne   .a
        pop   dx
        pop   bx
        pop   ax
        ret
    ; ----------------------
    msg  db 10, 14, 'Message 1', 0
         db 10, 12, 'Message 2', 0
         db 10, 10, 'Message 3', 0
    

    This is a MASM version that produces an .EXE executable:

    stack   segment para stack 'stack'
    
         db 64 dup('stack***')            
    
    stack   ends                        
    ; -------------------------------- 
    dseg    segment para public 'data'
    
    msg  db 10, 14, 'Message 1', 0
         db 10, 12, 'Message 2', 0
         db 10, 10, 'Message 3', 0
    
    dseg    ends
    ; -------------------------------- 
    cseg    segment para public 'code'
    
    prog proc far                      
        assume cs:cseg, ds:dseg, ss:stack 
        
        mov   ax, dseg                   
        mov   ds, ax                       
    
        mov   ax, 0x0003    ; BIOS.SetVideoMode 80x25 16-color text
        int   0x10
        mov   dx, 0x184F    ; LowerRightCorner (79,24)
        xor   cx, cx        ; UpperLeftCorner (0,0)
        mov   bh, 0xF0h     ; Attribute for blinking BlackOnWhite
        mov   ax, 0x0600    ; BIOS.ClearWindow
        int   0x10
        mov   si, OFFSET msg
        call  PrintAT       ; -> SI
        call  PrintAT       ; -> SI
        call  PrintAT       ; -> SI
    
        mov   ah, 0x00      ; BIOS.WaitKeystroke
        int   0x16          ; -> AX
        mov   ax, 0x0003    ; BIOS.SetVideoMode 80x25 16-color text
        int   0x10
        mov   ax, 0x4C00    ; DOS.TerminateWithReturncode
        int   0x21
    ; ----------------------
    ; IN (si) OUT (si)
    PrintAT:
        push  ax
        push  bx
        push  dx
        lodsw
        mov   dx, ax        ; DH is Row, DL is Column
        mov   bh, 0         ; DisplayPage
        mov   ah, 0x02      ; BIOS.SetCursorPosition
        int   0x10
    
        jmp   .b
    .a: mov   dl, al
        mov   ah, 0x02      ; DOS.PrintCharacter
        int   0x21          ; -> AL
    .b: lodsb
        cmp   al, 0
        jne   .a
        pop   dx
        pop   bx
        pop   ax
        ret
    prog    endp
    
    cseg    ends
    ; --------------------------------
    end prog