Search code examples
assemblydosx86-16

Relationship between AL and DL or AX and DX when using int 21h output functions?


I'm just curious with the relationship of al and dl because when I input a character and later I'll print it after printing a certain another character, the value of al suddenly changed. Here's the sample code below. Thanks!

cseg segment para 'code'
assume cs:cseg; ds:cseg; ss:cseg; es:cseg
org 100h
start: jmp begin

begin:  
mov ax, 03h
int 10h

mov ah, 01h
int 21h

mov ah, 02h
mov dl, '&'
int 21h

mov ah, 02h
mov dl, al
int 21h

int 20h
cseg ends
end start

The output should be like the:

(char)&(char)

But is appearing is:

(char)&&

Solution

  • Your problem is that function 02h of interrupt service 21h returns in AL the ASCII code of the last printed character.

    In your case, when you request service 02h of INT 21h to print '&', register AL will be overwritten with ASCII code '&'.

    You should backup the content of AL to another register (e.g. mov cl, al) before calling service 02h of INT 21h if your intent is to use that value afterwards.

    Check this reference for more info on the service you are using.