News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

The question of INT21H

Started by buli, February 23, 2016, 12:48:22 AM

Previous topic - Next topic

buli

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

FORTRANS

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.   

dedndave

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

buli

Thanks Steve :biggrin:
Thanks dedndave :biggrin:
I generally understand.
I will keep searching for some reference of this case.

MichaelW

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.

Well Microsoft, here's another nice mess you've gotten us into.