You are on page 1of 5

Lecture Notes in Assembly Language Programming

;PROGRAM1.asm - Prototype of an Assembly Language Program

by J.A.Agbayani

.MODEL SMALL .STACK 64 .DATA .CODE main PROC FAR .............. .............. .............. .............. .............. main ENDP END main ;stop the main procedure __________________________________________________________________________ ;PROGRAM2.asm More than one procedure .MODEL SMALL .STACK 64 .DATA .CODE PROC FAR .............. .............. CALL subp .............. .............. ENDP

main

;call a sub-procedure called subp

main subp

PROC NEAR .............. .............. .............. .............. ;all sub-procedures RET ;should end with RET subp ENDP END main __________________________________________________________________________ ;PROGRAM3.asm 1st two and Last two instructions inside ;the main procedure .MODEL SMALL .STACK 64 .DATA .CODE main PROC FAR MOV AX,@DATA ;get the address of DATA segment MOV DS,AX ............... ............... ............... MOV AH,4CH ;exit to DOS INT 21H main ENDP END main

Page 1 of 5

Lecture Notes in Assembly Language Programming


;PROGRAM4.asm - Input a character .MODEL SMALL .STACK .DATA .CODE PROC FAR MOV AX,3 INT 10H MOV AH,1 INT 21H MOV AH,4CH INT 21H ENDP END main

by J.A.Agbayani

main

;clrscr() ;input a character ;character typed stored to AL ;exit to DOS

main

__________________________________________________________________________ ;PROGRAM5.asm - Output a character .MODEL SMALL .STACK .DATA .CODE PROC FAR MOV AX,3 INT 10H MOV DL,65 MOV AH,2 INT 21H INC DL MOV AH,2 INT 21H MOV AH,4CH INT 21H ENDP END main

main

;clrscr() ;ASCII code of 'A' ;output a character ;'B' ;display it ;exit to DOS

main

Screen Output:

Page 2 of 5

Lecture Notes in Assembly Language Programming


;PROGRAM 6. Output a string

by J.A.Agbayani

myname main

.MODEL SMALL .STACK .DATA DB 13,10,"Jess Agbayani$" .CODE PROC FAR MOV AX,@DATA ;get the address of DATA segment MOV DS,AX MOV AX,3 INT 10H MOV DX,OFFSET myname MOV AH,9 INT 21H MOV AH,4CH INT 21H ENDP END main ;clrscr() ;LEA DX,name ;output a STRING ;exit to DOS

main

Screen Output:

-----------------------------------------TO RUN THE PROGRAM -----------------------------------------STEP 1. Compile the program (program6.asm) C:\>TASM program6 <Enter> STEP 2. Link the program (program6.obj) C:\>TLINK program6 <Enter> STEP 3. Execute the program (program6.exe) C:\>program6 <Enter> DOWNLOAD TASM COMPILER (TASM.EXE and TLINK.EXE) AT http://www.geocities.com/jessagba/tasm.html http://www.geocities.com/txtassembly

Page 3 of 5

Lecture Notes in Assembly Language Programming


;PROGRAM 7. Output a string

by J.A.Agbayani

myname

nline main

.MODEL SMALL .DATA DB 13,10,Name: Jess Agbayani DB 13,10,Address: Deparo, Caloocan City DB 13,10,Nationality: Filipino DB 13,10,Gender: Male$ DB 13,10,$ .CODE PROC FAR MOV AX,@DATA ;get the address of DATA segment MOV DS,AX MOV AX,3 INT 10H MOV DX,OFFSET myname MOV AH,9 INT 21H MOV DX,OFFSET nline INT 21H MOV AH,4CH INT 21H ENDP END main ;clrscr()

;output a STRING ;new line ;exit to DOS

main

Screen Output:

Page 4 of 5

Lecture Notes in Assembly Language Programming


;FILENAME: SAMPLE.ASM - My first assembly language program. ;AUTHOR: J. Agbayani .MODEL small .STACK 64 .DATA prompt1 DB "Input a character: $" prompt2 DB 0AH,0DH,"You typed: $" prompt3 DB 0AH,0DH,"Want More? $" .CODE main PROC FAR MOV AX,@data MOV DS,AX start: MOV AX,3 INT 10H MOV DX,OFFSET prompt1 MOV AH,9 INT 21H MOV AH,1 INT 21H MOV BL,AL MOV DX,OFFSET prompt2 MOV AH,9 INT 21H MOV DL,BL MOV AH,2 INT 21H MOV DX,OFFSET prompt3 MOV AH,9 INT 21H MOV AH,1 INT 21H CMP AL,'Y' JE start CMP AL,'y' JE start MOV AH,4CH INT 21H ENDP END main ;clrscr();

by J.A.Agbayani

;cout<<prompt1; ;press a character ;store character to BL ;cout<<prompt2

;display character ;Do you want more?

;press any key

;jump if equal to start label

;exit to DOS ;end of program

main

Program OUTPUT: Input a character: A <Enter> You typed A Want more? Y

Page 5 of 5

You might also like