Author Topic: The question of INT21H  (Read 1542 times)

buli

  • Regular Member
  • *
  • Posts: 7
The question of INT21H
« on: February 23, 2016, 12:48:22 AM »
Code: [Select]
.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

  • Member
  • ****
  • Posts: 944
Re: The question of INT21H
« Reply #1 on: February 23, 2016, 09:44:01 AM »
Hi,

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

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: The question of INT21H
« Reply #2 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

buli

  • Regular Member
  • *
  • Posts: 7
Re: The question of INT21H
« Reply #3 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.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: The question of INT21H
« Reply #4 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.

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