Step 2Start coding the real thing!!
I hope you know a little about CPUs, if not... then maybe you will have a little dificulty to undestand this!
We will be using function 09h (WRITE STRING TO STANDARD OUTPUT) of DOS Interrupt (INT 21h).
Some description about this function:
AH = 09h - WRITE STRING TO STANDARD OUTPUT
Entry: DS:DX -> '$'-terminated string
Return: AL = 24h
Notes: C/Break are checked
In assembly, all text after ';' are comments... but note that DEBUG.EXE doesn't support that, so, don't type them
The DS (Data Segment) register always point the correct segmentation before the .COM is executed.
what we need is (in x86 assembly language):
MOV AH, 09h ; AH register is used on DOS Interrupt to define what function should call
MOV DX, OFFSET helloworldstring ; DX register will hold the offset of the string
INT 21h ; Call the DOS Interrupt
RET ; Return from call, in this case it will terminate our Hello World app
helloworldstring DB "Hello World!$" ; the string himself...
the point is that we will not be using a assembler, but DEBUG.EXE, so we need to type this in a different way (note that numbering values are in hexadecimal):
- a 0100
????:0100 MOV AH, 09
????:0102 MOV DX, 0000
????:0105 INT 21
????:0107 RET
????:0108 DB "Hello World!$"
????:0115 (Press ENTER)
Notice i've pointed DX to :0000 because i didn't knew where the string should be stored. Now that i know is at :0108, i can easilly fix that opcode:
- a 0102
????:0102 MOV DX, 0108
????:0105 (Press ENTER)
Optionally, you can replace "RET" with "INT 20" (INT 20h = Terminate Application) or use function 0x4C of DOS Interrupt:
MOV AH, 4C ; Function 0x4C
MOV AL, 00 ; Return ERRORCODE 0 (OK!)
INT 21 ; Call DOS Interrupt
But if your following this tutorial for the first time, is better to use "RET" for now...
We are done coding!! Pretty easy, hum? :)
No? Don't undestand what it do? Well..
MOV AH, 09 ; Make Register AH (8-Bits Register) be 0x09
MOV DX, 0000 ; Make Register DX (16-Bits Register) be 0x0000
INT 21 ; Call Interrupt 0x21 (0x21 = DOS Interrupt)
RET ; Return from a call (No, it has nothing to do with "INT 0x21", but will terminate the app)
Now don't play around if you don't know what your doing or DEBUG.EXE will possibly crash (if your in DOS, that means you have to reboot your PC).
Lastlly if you don't undestand what is AH / DX / DS Registers i've talked about? See a register as a tiny 8/16 bits memory cell where the CPU use to process the data (because using memory in RAM is actually slower that using registers).
Some general use registers:
AL,BL,CL,DL = 8-Bits Registers
AH,BH,CH,DH = 8-Bits Registers
AX,BX,CX,DX = 16-Bits Registers, this is actually *L (Low Byte) and *H (High Byte) together
Some segment registers:
CS = 16-Bits Register (Code Segment)
DS = 16-Bits Register (Data Segment)
Some ASM example, note that RIGHT copy to LEFT:
MOV AL, 0x05 ; AL = 0x05, BL = ???
MOV BL, AL ; AL = 0x05, BL = 0x05
MOV AL, 0x02 ; AL = 0x02, BL = 0x05
Next we will debug and check the code...
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|










































