'What does it mean by "MOV AH, 4CH" in assembly language?

Most of the assembly code is terminate by the following instructions

MOV AH, 4CH
INT 21H

What does it mean by "MOV AH, 4CH" ?



Solution 1:[1]

MOV AH, 4CH means store (or "move" (w)) the hexadecimal value 4C into register (w) AH.

(Note that the verb "move" is used historically but it is quite an unfortunate choice for a verb, because when you move something it ceases to exist in its old location and can only be found in its new location, whereas in reality all "move" instructions actually copy data: once the instruction completes, the value can be found in both locations. It is amazing how, in a discipline which requires so much logic, people can be so illogical in the language they use.)

INT 21H means invoke the interrupt (w) identified by the hexadecimal number 21.

That was the answer to the question "What does it mean by "MOV AH, 4CH" in assembly language?" However, I am pretty sure that the OP did not mean to ask what this means in assembly language; the OP probably meant to ask what it means in MS-DOS.

So, here it goes:

MS-DOS (or more likely nowadays something emulating MS-DOS) catches invocations to interrupt 21h and performs some operating-system-dependent function which is identified by the value of register AH.

According to the MS-DOS API (w), invoking interrupt 21h while AH = 4Ch causes the current process to terminate and uses the value of register AL as the exit code of the process.

Solution 2:[2]

MOV Code Works Like This: MOV Value1,Value2.
It Puts Value2 into Value1. But You can't Move something From variable to variable in memory. You Can Use This Code Like These:

  • Register to Register
  • Register to Memory
  • Memory to register

This code that you wrote puts 4c hexadecimal (=76 decimal) into ah register. you ask why do we do that? We always have to put some number(number of the function) into ah register when we are using an interrupt.

on ah=4ch int 21h , the program will terminate control to the operating system.(end the program) And int 21h is a dos interrupt.Example:

ah=9h , dx=offset (string + '$') ,int 21h . writes the string at the cursor position.

ah=6h , ch=starting row,cl=starting column,dh=ending row,dl=ending column,al=number of lines,bh=attribute, int 10h clears the defined area and writes the attribute on it.

ah=2h , dh=row,dl=column,bh=page number , int 10h

tip: video memory is divided to 8 pages(0 to 7). we're using the 0 page in this example.

the program:

datasg segment para 'data'
    msg db 'Hello world$'
datasg ends
codesg segment para 'code'
    example proc far
        assume cs:codesg,ds:datasg    ;lead the assembler to know the segments.
        mov ax,datasg                 ;this is because ds cannot be vaulued directly.
        mov ds,ax                     ;move the data segment offset to its register.
        mov ah,6h
        mov al,25
        mov ch,0
        mov cl,0
        mov dh,24
        mov dl,79
        mov bh,0fh
        int 10h
        mov ah,2h
        mov dh,2
        mov dl,4
        mov bh,0
        int 10h
        mov ah,9h
        mov dx,offset msg
        int 21h
        mov ah,8h
        int 21h
        mov ah,4ch
        int 21h
    example endp
codesg ends
end main

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Peter Cordes