Search code examples
masm32

Cannot get CR and LF to display


I'm trying to display the carriage return and line feed in my code but it does not work. If I print out the codes as a string it works. Help needed. Thanks in advance.

; A 16-bit DOS program that receives a single char from STDIN and then prints it out to ;STDOUT

    .MODEL small
    .stack 100h

    .data

    char_prompt     db  'Please input a character: ','$'
    out_msg1        db  'Character entered is: ','$'
    out_msg2         db 0dh,0ah, '$'    

    .code
    start:

    mov ax, @data
    mov ds, ax ; Set DS segment

    mov dx, offset char_prompt; display msg1
    mov ah,9    
    int 21h    

    mov ah, 01h ;store char in BL
    int     21h
    mov bl, al

    mov dl, 0dh; ;output CR
    mov ah, 02h  
    int 21

    mov dl, 0ah ;output LF
    mov ah, 02h
    int 21

    mov dx, offset out_msg1 ;display msg2
    mov ah,9
    int 21h    

    mov     dl, bl ;display char  
    mov     ah, 02h  
    int 21h

    mov ax, 4C00h
    int 21h

    end start

Solution

  • Your code is wrong: Look carefully at the int parts:

    mov dl, 0dh; ;output CR
    mov ah, 02h  
    int 21
    
    mov dl, 0ah ;output LF
    mov ah, 02h
    int 21
    

    What are you missing? INT 21 is NOT correct!! It should be INT 21H