2

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?

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Mitul
  • 59
  • 5
  • 3
    *After running it the value 35h will first moved to al and then displayed.* No, [INT21h/Ah=2](http://www.ctyme.com/intr/rb-2554.htm) requires the character to write in `DL`, it does not mention copying it to `AL` first. – vitsoft Sep 17 '22 at 09:13
  • @vitsoft So then DL is responsible for displaying the data – Mitul Sep 17 '22 at 09:16
  • 3
    Int 21h with an AH value of 2 is a system call that prints the character in _DL_. _DL_ just happens to be the register that was chosen as a parameter to Int 21h/AH=2 (write a character) – Michael Petch Sep 17 '22 at 09:34
  • @MichaelPetch thanks man for the help. it all makes sense now – Mitul Sep 17 '22 at 09:49
  • @MichaelPetch they why when we display the data before that step it's been passed to al? – Mitul Sep 17 '22 at 09:53
  • Look at where DOS input and output single-character calls leave the return value / look for the arg, respectively. http://spike.scu.edu.au/~barry/interrupts.html – Peter Cordes Sep 17 '22 at 19:47

1 Answers1

2
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.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76