Author Topic: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?  (Read 157 times)

bugthis

  • Regular Member
  • *
  • Posts: 22
When i have the following code for JWASM in DOS:
Code: [Select]
MOV AH, 02h
INT 21h

Is it then guaranteed that INT 21h will never change the content of AH?

I ask because of this:
Code: [Select]
MOV DL, 0Dh ; Output CR
MOV AH, 02h
INT 21h
MOV DL, 0Ah ; Output  LF
MOV AH, 02h          <---- If INT 21h does not change AH, then i won't need that line. One operation less.
INT 21h




jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #1 on: November 29, 2022, 01:18:31 AM »
If some forum members write "sure, go ahead!", will you delete that line when writing a mission critical software?

FORTRANS

  • Member
  • *****
  • Posts: 1215
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #2 on: November 29, 2022, 01:31:35 AM »
Hi,

   Yes, in general, MS-DOS does seem to preserve AH across
an Int 21H function call.  But I cannot find this documented
anywhere.  Also function 59H "Get Extended Error" is
documented to change all registers except SS:SP and CS:IP.
So I won't make any recommendation in this situation.

Regards,

Steve N.

HSE

  • Member
  • *****
  • Posts: 2252
  • AMD 7-32 / i3 10-64
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #3 on: November 29, 2022, 02:50:42 AM »
Is it then guaranteed that INT 21h will never change the content of AH?

No. In early MS-DOS versions INT 21H return errors in AX. You can assume same thing in later versions. 

Equations in Assembly: SmplMath

_japheth

  • Member
  • **
  • Posts: 100
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #4 on: November 29, 2022, 03:20:22 AM »

> Some members can't live without insulting others. It tells us a lot about them.

Since you used the little word "us": What is it supposed to tell me?

Because, psychologically, I see virtually no difference in insulting someone and ridicule or slur someone. The purpose is always to daunt the opponent - and I suppose that quite common (and healthy  :bgrin: ) human nature.
The road to hell is paved with good intentions.

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #5 on: November 29, 2022, 03:36:29 AM »
I see virtually no difference in insulting someone and ridicule or slur someone.

IMHO none of these habits are beneficial for a programming forum.

C3

  • Regular Member
  • *
  • Posts: 15
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #6 on: November 29, 2022, 04:50:55 AM »
Is it then guaranteed that INT 21h will never change the content of AH?

No. In early MS-DOS versions INT 21H return errors in AX. You can assume same thing in later versions.

The best way would be Ralp Browns Interrupt listings (MS-DOS era). There is what goes in the registers, and what comes out to registers and flags. No need to guess values.

FORTRANS

  • Member
  • *****
  • Posts: 1215
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #7 on: November 29, 2022, 06:13:25 AM »
Hi,

   I checked some documentation.  MS-DOS 1.x returns
error codes in AL, a zero means no error.  MS-DOS 2+
returns with the carry bit set on to indicate an error.  Then
AX contains the error number.  Just a rough rule of thumb
though.

Cheers,

Steve

Shintaro

  • Member
  • **
  • Posts: 170
  • Thoughts create Realaties
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #8 on: November 29, 2022, 10:50:31 AM »
from an old Reference (About 1991):
- Register AX may be altered, its contents are not guaranteed.
- If an error occurs, CF is set to 1 and AX contains a simple error code.
- Int 21, 59 can be used to determine the cause.
- Most Int 21 functions do not restore the flags to pre-interrupt state to allow returning of information via the flags register.
“Wyrd bið ful āræd. Fate is inexorable.”

bugthis

  • Regular Member
  • *
  • Posts: 22
Re: JWASM: Do "MOV AH, 02h" and "INT 21h" never change the content of AH?
« Reply #9 on: December 01, 2022, 08:40:01 PM »
Thanks to you all for the clarification. Then i will keep that extra
Code: [Select]
MOV AH, 02h line.