Open Library

Return to DOS ressources.

Tutorial - TASM

Assembly with TASM (Turbo Assembler) on DOS.

Afficher un message "Hello World".

.MODEL TINY     ;The MODEL directive defines the memory model used
                ;by this program.
                ;The TINY model uses a maximum of 64K bytes for
                ;the CODE, DATA and STACK sections of the program.

.STACK          ;The STACK directive allows the compiler to create
                ;a STACK segment.

.DATA           ;The DATA directive allows the compiler to create
                ;a DATA segment in order to place variables there
                ;and to associate physical memory addresses with it.
        
		;Declaration of a string of character.
		;the 2 numbers 13 followed by 10 indicates a carriage return
		;The $ character indicates the end of the character string.
		HELLO db "Hello World!",13,10,'$'

.CODE           ;The CODE directive allows the compiler to create
                ;a CODE segment that contains the instructions
                ;program executables.

MAIN PROC       ;Start of the main procedure MAIN of the program.
        
        mov ax, @DATA   ;Places the address of DATA in the AX register.
        mov ds, ax      ;Places the value of AX into DS (Data Segment).
                        ;Because we cannot directly place the address
                        ;from DATA to DS so we pass through the AX register.

        mov dx, offset HELLO    ;Points to the string HELLO
        
        mov ah, 9               ;Print screen function of
                                ;the string of characters.
        
        int 21h                 ;Execute the function.

        mov ax, 4C00h           ;Program closing function.
        int 21h                 ;Execute the function.

MAIN ENDP       ;End of the program's MAIN procedure.
END MAIN        ;Indicates the end of the file by specifying here
                ;the entry point of the MAIN program.

Display a pixel on the screen in VGA mode 13h.

.MODEL SMALL    ;Sets the memory model to SMALL.
                ;This memory model allows you to use it to the maximum
                ;64K bytes for DATA and 64K bytes for the CODE.
                ;This model is commonly used.

.STACK 100h     ;Reserve 100h bytes for the STACK segment.

.CODE           ;CODE segment

MAIN PROC       ;Start of the main procedure MAIN of the program.
        
        mov ax,13h      ;Initializing 13h mode:
        int 10h         ;VGA mode in 256 colors 320x200.

        mov ax,0A000h   ;0A000h is the video memory address of VGA mode 13h
        mov es,ax       ;We load the video memory address into ES.

        mov bx,7D64h    ;Positioning a pixel in the center of the screen.
                        ;7D64h in hexadecimal = 32160 in decimal.

        mov al,0ah      ;Store the color in the al register.

        mov es:[bx],al  ;We place the offset (memory displacement) BX
                        ;on memory address ES, color AL.
                        ;Which allows to directly display a pixel
                        ;colored on the screen.

        mov ah,07h      ;Waits for a key to be pressed without displaying
        int 21h         ;the character
        
        mov ah,00h      ;Return to standard DOS text mode:
        mov al,03h      ;80 columns x 25 rows.
        int 10h

        mov ah,4ch      ;Terminates the current DOS process.
        int 21h

MAIN ENDP       ;End of the program's MAIN procedure.
END MAIN        ;Indicates the end of the file and the end of
                ;main function.

Display a line on the screen in VGA mode 13h.

.MODEL SMALL    ;Sets the memory model to SMALL.
                ;This memory model allows you to use it to the maximum
                ;64K bytes for DATA and 64K bytes for CODE.
                ;This model is commonly used.

.STACK 100h     ;Reserve 100h bytes for the STACK segment.

.CODE           ;CODE segment

MAIN PROC       ;Start of the main procedure MAIN of the program.
        
        mov ax,13h      ;Initializing 13h mode:
        int 10h         ;VGA mode in 256 colors 320x200.

        mov ax,0A000h   ;0A000h is the video memory address of VGA mode 13h
        mov es,ax       ;We load the video memory address into ES.

        mov bx,7D00h    ;Positioning on the middle horizontal line.
                        ;7D00h in hexadecimal = 32000 in decimal.

        mov al,22h      ;Store the color in the al register.

        mov cx,320      ;The CX register serves as a counter for the line.
                        ;This line will be incremented by one pixel per unit.
                        ;The line will therefore be 320 pixels long here.
        LINE:
                mov es:[bx],al  ;Positioning of the new pixel to display.
                inc bx          ;We increment the BX register by 1.
                loop LINE       ;Loop to LINE by decrementing CX by 1
                                ;until CX reaches zero.
                                ;So the loop continues as long as CX is
                                ;greater than zero. 
                                ;This loop will therefore display a line.

        mov ah,07h      ;Waits for a key to be pressed without displaying
        int 21h         ;The character
        
        mov ah,00h      ;Return to standard DOS text mode:
        mov al,03h      ;80 columns x 25 rows.  
        int 10h

        mov ah,4ch      ;Terminates the current DOS process.
        int 21h

MAIN ENDP       ;End of the program's MAIN procedure.
END MAIN        ;Indicates the end of the file and the entry point of 
                ;the program.


Display a rectangle in VGA mode 13h.

.MODEL SMALL    ;Sets the memory model to SMALL.
                ;This memory model allows you to use it to the maximum
                ;64K bytes for DATA and 64K bytes for CODE.
                ;This model is commonly used.

.STACK 100h     ;Reserve 100h bytes for the STACK segment.

.CODE           ;CODE segment

MAIN PROC       ;Start of the main procedure MAIN of the program.
        
        mov ax,13h      ;Initializing 13h mode:
        int 10h         ;VGA mode in 256 colors 320x200.

        mov ax,0A000h   ;0A000h is the video memory address of VGA mode 13h
        mov es,ax       ;We load the video memory address into ES.

        mov bx,7D64h    ;Positioning a pixel in the center of the screen.
                        ;7D64h in hexadecimal = 32160 in decimal.

        mov al,2Bh      ;Store the color in the al register.

        mov di,20       ;DI contains the height of the rectangle
        ROW:            ;Label ROW (Column)

                mov cx,25       ;CX = counter for the width of the rectangle.

                LINE:           ;LINE Label (Line)
                        
                        mov es:[bx],al  ;Positions a pixel on the screen.
                        inc bx          ;We increment the BX register by 1.
                        
                        loop LINE       ;Loop LINE and decrement CX by 1.
                                        ;until CX reaches zero.
                                        ;End of LINE loop.
                                        ;A line of the rectangle is displayed.
                
                add bx,320      ;We add 320 to the BX memory offset:
                                ;Move to the next line.
                sub bx,25       ;Subtract from BX the length defined by CX.
                dec di          ;Decrement DI by 1 on each new line
                                ;displayed so that the height matches
                                ;to that defined above.
                
                cmp di,0        ;Compare DI to 0.
                jne ROW         ;If DI is not equal to zero:
                                ;We enter the ROW loop again in order
                                ;to create a new line until
                                ;the height of the rectangle is reached. DI
                                ;will be equal to zero in this case.
               
        mov ah,07h      ;Waits for a key to be pressed without displaying
        int 21h         ;The character
        
        mov ah,00h      ;Return to standard DOS text mode:
        mov al,03h      ;80 columns x 25 rows. 
        int 10h

        mov ah,4ch      ;Terminates the current DOS process.
        int 21h

MAIN ENDP       ;End of the program's MAIN procedure.
END MAIN        ;Indicates the end of the file and the main function
                ;of the program.

Return to top of the page.