9

Most of the assembly code is terminate by the following instructions

MOV AH, 4CH
INT 21H

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

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Shams Nahid
  • 6,239
  • 8
  • 28
  • 39

4 Answers4

14

In Intel assembly, MOV AH, something means store (or "move" (w)) something 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.)

4CH is the hexadecimal number 4C, which is 76 in base-10.

The H suffix signifies to the assembler that it should interpret the number as hexadecimal. Confusion with register names such as AH (and also with labels, such as hash:) is avoided by requiring that all numbers, regardless of radix, must start with a decimal digit (0-9). AH does not start with a decimal digit, therefore it is not a number.

If you wanted to represent the base-10 number 10 in hexadecimal, this would normally be just A, but in intel assembly you would have to say 0AH. The use of 0 as a prefix does not change the value of the number, but it ensures that the number starts with a decimal digit so it will be interpreted as a number and not as the name of the register AH.

That was the answer to the question "What does it mean by MOV AH, 4CH in assembly language?" However, it is possible that the OP did not mean to ask what this means in assembly language; the OP may have intended to ask what MOV AH, 4CH followed by INT 21H means in MS-DOS.

So, here it goes:

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

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.

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
11

DOS interrupt int 21/4Ch is EXIT - TERMINATE WITH RETURN CODE, the content of al is used as the return code and the process is terminated. The documentation comes with the following note:

Unless the process is its own parent (see #01378 [offset 16h] at AH=26h), all open files are closed and all memory belonging to the process is freed. All network file locks should be removed before calling this function

fuz
  • 88,405
  • 25
  • 200
  • 352
1

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
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thanks for this explanation, really – Quwaysim Mar 21 '21 at 17:38
  • *We always have to put some number(number of the function) into ah register when we are using an interrupt.* Not always, see e.g. interrupts 0x11 (get BIOS equipment list), 0x12 (get memory size), 0x19 (system reboot) or 0x20 (exit to operating system), – Sebastian Nov 15 '22 at 05:56
-1

4ch means that this program should be terminated and the control from program should assign to the operating system. After calling this interrupt the memory will be cleared. And one other thing: You should always assign this value to AH register.

Sebastian
  • 1,834
  • 2
  • 10
  • 22
  • 1
    This doesn't seem to add anything that wasn't already explained in earlier answers, especially Mike's. Please read existing answers before adding your own. Also, what memory will be cleared? The whole machine? No, DOS is still running, and the BIOS data area still holds stuff. I don't think DOS would even know which areas of memory your program even wrote, or would spend time zeroing them. Your program is no longer running, but the bytes it stored in memory will still be there until something else reuses that memory. – Peter Cordes Nov 15 '22 at 07:07