The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: buli on February 23, 2016, 12:48:22 AM

Title: The question of INT21H
Post by: buli on February 23, 2016, 12:48:22 AM
.MODEL SMALL
         .STACK
         .DATA
         .CODE
          MAIN:
          MOV AX,0506H ;AX=0506H
          MOV CL,11       ;CL=0BH
          AAD                 ;AX=0038H
          DIV CL             ;AX=0105H
          MOV DL,AH
          ADD DL,30H
          MOV AH,02H
          INT 21H
          MOV DL,AL
          ADD DL,30H
          MOV AH,02H
          INT 21H
          MOV AH,4CH
          INT 21H
END MAIN

Sorry,i am beginner. I got wrong when i try to display the result of DIV.I expected the screen will show 15, but it show 1a.
And i tried to use MOV BX,AX ,and use BX to show the value of AX. It got right!!
Do the INT21H have any  restriction on AX ?
Title: Re: The question of INT21H
Post by: FORTRANS on February 23, 2016, 09:44:01 AM
Hi,

Quote from: buli on February 23, 2016, 12:48:22 AM
Do the INT21H have any  restriction on AX ?

   The MS-DOS Programmer's Reference, version 5.0, does not directly
address what registers are preserved or not.  AL and AX often return
error codes.  But you will have to see for yourself on a case by case
basis.  If you have a copy of the reference, it is pretty good describing
register usage.  But AX should probably be regarded as volatile.

HTH,

Steve N.   
Title: Re: The question of INT21H
Post by: dedndave on February 24, 2016, 12:52:33 AM
in most cases, registers not used to pass arguments or return results are preserved
there are some cases (particularly with DOS 2.0 and earlier) where specific registers are not preserved
these were "accidental" cases, though (i think one of them forgot to preserve BP, for example)

however, you have the possibilty of other problems with the display of numbers greater than 9

what i suggest is
write a routine that will convert a binary value to ASCII decimal string in a memory buffer
after DIV, store the results in variables, then pass the variables to the routine
that way, you don't have to mess with a bunch of push/pop trying to keep things preserved
Title: Re: The question of INT21H
Post by: buli on February 24, 2016, 02:55:40 AM
Thanks Steve :biggrin:
Thanks dedndave :biggrin:
I generally understand.
I will keep searching for some reference of this case.
Title: Re: The question of INT21H
Post by: MichaelW on February 27, 2016, 09:36:38 AM
I can't recall seeing any specific recommendations for MS-DOS apps, but obviously the callee will need to preserve the segment registers and SP, and also probably BP, assuming that it will be called by compiler-generated code.