Reputation: 59
I just started learning assembly and I have a little bit of confusion regarding DL (data register) and AL (accumulated register).
mov dl,35h
mov ah,2
int 21h
After running it, the value 35h will first be moved to AL and then displayed.
While when taking the input and output program:
mov ah, 1
int 21h
mov dl,al
mov ah,2
int 21h
The value is first copied to DL by using the mov
but why can't we display it direct from AL as it is already inputted in AL?
Upvotes: 2
Views: 150
Reputation: 39166
mov dl,35h mov ah,2 int 21h
After running it, the value 35h will first be moved to AL and then displayed.
At first I thought you were referring to the fact that this DOS function does indeed copy DL to AL as part of its normal operation. This function returns with the inputted character in the AL register. Maybe that's what confused you?
You might want to take a look at Displaying characters with DOS or BIOS.
The DOS.KeyboardInputWithEcho function 01h delivers you the character in the AL register, but the DOS.DisplayCharacter function 02h expects from you a character in the DL register. That's the reason why you need that extra put in mov dl, al
instruction.
why can't we display it direct from AL as it is already inputted in AL?
If you would have chosen the BIOS.Teletype function 0Eh to display the character, then you would not have had to copy AL to DL since that BIOS function does expect the character in the AL register.
For every api call you make, be it BIOS or DOS, you have to find out what information is required in what register(s) and what register(s) will contain the result. No guessing involved!
Ultimately, it's the designer of the api that made the choice of register and we can't but follow.
Upvotes: 2