What does it mean by "MOV AH, 4CH" in assembly language?
Solution 1
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
Solution 2
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 3
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
Related videos on Youtube
Shams Nahid
Having 4 years of experience as a Software Engineer specializing in Full-Stack development. Proficient in working with JavaScript frameworks and AWS Cloud Infrastructure. Collaborating with remote technical teams from the USA (ShiftSmart) and Singapore (LumenLab) for last 3 years. Along with web technologies, I am constantly expanding my skill sets in the Serverless and DevOps world. My professional goal is to work and grow in the field of Engineering and Software Architecture.
Updated on May 18, 2022Comments
-
Shams Nahid almost 2 years
Most of the assembly code is terminate by the following instructions
MOV AH, 4CH INT 21H
What does it mean by "MOV AH, 4CH" ?
-
Shams Nahid about 7 yearsHere I asked for "MOV AH, 4CH", Not INT 21H. "INT 21H" just came along with it.
-
-
Quwaysim about 3 yearsThanks for this explanation, really 👍