Skip to content

Latest commit

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Assembly

Input a character and print it

.MODEL SMALL.STACK 100H.CODEMAIN PROCMOVAH,1INT21H ; Input a characterMOVBL,ALMOVAH,2MOVDL,BL ; Print the input characterINT21H EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

001

Input a character and print it with a newline

; scan a character, print a new line and then print the input char.MODEL SMALL.STACK 100H.CODEMAIN PROCMOVAH,1 ; Scan the charINT21HMOVBL,ALMOVAH,2 ; Print the new lineMOVDL,0AH ; 0AH ascii code for new lineINT21HMOVDL,0DH ; Remove the space (cret 0dh)INT21HMOVAH,2 ; Print the charMOVDL,BLINT21H EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

002

Input multi-digit number and print

; input multidigit number and print.MODEL SMALL.STACK 100H.CODEMAIN PROC ; input a four digit numberMOVAH,1INT21HMOVBL,ALINT21HMOVBH,ALINT21HMOVCL,ALINT21HMOVCH,AL ;---------------------------------- ;print a new lineMOVAH,2MOVDL,0AHINT21HMOVDL,0DHINT21H ;---------------------------------- ;Print the 4 digit numberMOVAH,2MOVDL,BLINT21HMOVAH,2MOVDL,BHINT21HMOVAH,2MOVDL,CLINT21HMOVAH,2MOVDL,CHINT21H ;---------------------------------- EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

003

Print a string

; Print a string.MODEL SMALL.STACK 100H.DATA STR1 DB 'We need to print a string.$' STR2 DB 'STR1, STR2 & STR3 are string variables...$' STR3 DB 'Doller sign in the null char for the string..$'.CODEMAIN PROCMOVAX, @DATA ;initializing the data segmentMOVDS,AX ; Print the stringsLEADX, STR1 ;Load Effective AddressMOVAH,9 ;Print the 1st stringINT21HMOVAH,2 ;New LineMOVDL,0AHINT21HMOVDL,0DHINT21HLEADX, STR2MOVAH,9 ;Print the 2nd stringINT21HMOVAH,2 ;New LineMOVDL,0AHINT21HMOVDL,0DHINT21HLEADX, STR3MOVAH,9 ;Print the 3rd stringINT21H EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

004

Add two digits

; add two digits.MODEL SMALL.STACK 100H.CODEMAIN PROC ; input two digit [a b format]MOVAH,1INT21HMOVBL,ALMOVAH,1 ; scan a spaceINT21HMOVCL,ALMOVAH,1INT21HMOVCH,ALMOVCL,BL ;Keep the value of a for print result ;----------------------------ADDBL,CH ; BL = BL + CHSUBBL,30H ; BL = BL - 48, make the result ;Print the result [a + b = c format]MOVAH,2 ; New LineMOVDL,0AHINT21HMOVDL,0DHINT21HMOVDL,CL ; print aINT21HMOVDL,20H ; print a spaceINT21HMOVDL,2BH ; print a +INT21HMOVDL,20H ; print a spaceINT21HMOVDL,CH ; print aINT21HMOVDL,20H ; print a spaceINT21HMOVDL,3DH ; print an =INT21HMOVDL,20H ; print a spaceINT21HMOVDL,BL ; print the result cINT21H ;---------------------------- EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

005

Declare variable, input and print the variable

; variable declaration, initializing the; value and scan a variable.MODEL SMALL.STACK 100H.DATA A DB 3 ; A = 3 B DB ? ; value isn't initialized.CODEMAIN PROCMOVAX, @DATA ; initializing the data segmentMOVDS,AX ; scan the value of BMOVAH,1INT21HMOV B,AL ;--------------------MOVAH,2 ; new lineMOVDL,0AHINT21HMOVDL,0DHINT21H ; print the value of the two variable ; print the value of AMOVAH,2ADD A,48 ; to make the ascii value of 3MOVDL, A ;ADD DL, 48 ; to make the ascii value of 3INT21HMOVDL,20H ; print a spaceINT21H ; print the value of BMOVDL, BINT21H ;-------------------- EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

006

Arithmetic operation on variables

.model small.stack 100h.data a db ? b db ? c db ? d db ? e db ? f db ?.codemain procmovax, @datamovds,ax ; input a bmovah,1int21hmov a,alint21h ; spacemovbl,alint21hmov b,al ;--------------------- ; add c = a + bmovbl, amov c,blmovbl, badd c,blsub c,48 ;--------------------- ; sub d = a - bmovbl, amov d,blmovbl, badd d,blsub d,54 ;--------------------- ; print a + b = cmovah,2 ; new linemovdl,0ahint21hmovdl,0dhint21hmovdl, a ; print aint21hmovdl,20h ; spaceint21hmovdl,2bh ; +int21hmovdl,20h ; spaceint21hmovdl, b ; print bint21hmovdl,20h ; spaceint21hmovdl,3dh ; =int21hmovdl,20h ; spaceint21hmovdl, cint21h ;--------------------- ; print a - b = dmovah,2 ; new linemovdl,0ahint21hmovdl,0dhint21hmovdl, a ; print aint21hmovdl,20h ; spaceint21hmovdl,2dh ; -int21hmovdl,20h ; spaceint21hmovdl, b ; print bint21hmovdl,20h ; spaceint21hmovdl,3dh ; =int21hmovdl,20h ; spaceint21hmovdl, dint21h ;--------------------- exit:movah,4chint21h main endpend main

007

Conditional statement

; conditional statement.MODEL SMALL.STACK 100H.DATA GRTR DB ' > $' SMLR DB ' < $' EQAL DB ' = $'.CODEMAIN PROCMOVAX, @DATAMOVDS,AX ; input 2 numbers a bMOVAH,1INT21HMOVBL,ALINT21H ; SpaceMOVCL,ALINT21HMOVCL,AL ;-----------------------MOVAH,2MOVDL,0AH ; new lineINT21HMOVDL,0DHINT21HCMPBL,CLJG SEC2CMPBL,CLJL SEC3 SEC1: ; A == BMOVAH,2MOVDL,BLINT21HLEADX, EQALMOVAH,9INT21HMOVAH,2MOVDL,BLINT21HJMP EXIT SEC2: ; A > BMOVAH,2MOVDL,BLINT21HLEADX, GRTRMOVAH,9INT21HMOVAH,2MOVDL,CLINT21HJMP EXIT SEC3: ; A < BMOVAH,2MOVDL,BLINT21HLEADX, SMLRMOVAH,9INT21HMOVAH,2MOVDL,CLINT21H EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

008

Loops

; loop.MODEL SMALL.STACK 100H.DATA TXT DB ' Mellllooooowwww!!! $'.CODEMAIN PROCMOVAX, @DATAMOVDS,AXMOVAH,1INT21HMOVBL,ALSUBBL,48LOOP:MOVCX,0 ; Loops run in CXMOVCL,BLMOVBL,'5' SEC:MOVAH,2MOVDL,0AHINT21HMOVDL,0DHINT21HMOVDL,BLINT21HLEADX, TXTMOVAH,9INT21HINCBLLOOP SEC EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

009

Nested loops

; nested loop.MODEL SMALL.STACK 100H.CODEMAIN PROCMOVAH,1INT21HMOVBL,ALMOVAH,2 ; NEW LINEMOVDL,0AHINT21HMOVDL,0DHINT21HMOVBH,'1' LOOP1:MOVCL,'1' LOOP2:MOVAH,2 ; PRINT THE *MOVDL,2AHINT21HINCCLCMPCL,BHJLE LOOP2MOVAH,2 ; NEW LINEMOVDL,0AHINT21HMOVDL,0DHINT21HINCBHCMPBH,BLJLE LOOP1 EXIT:MOVAH,4CHINT21H MAIN ENDPEND MAIN

010

Array

; array.MODEL SMALL.STACK 100H.DATA A DB 10 DUP(0).CODEMAIN PROCMOVAX, @DATAMOVDS,AXXORBX,BX FOR:MOVAH,1INT21HMOVCL,ALCMPCL,0DHJE END_FOR ;SUB BL, 48MOV A[BX],CLINCBXJMP FOR END_FOR:MOVAH,2 ; NEWLINEMOVDL,0AHINT21HMOVDL,0DHINT21HMOVDX,BXINT21HMOVAH,4CHINT21H MAIN ENDPEND MAIN

011

About

A handbook for Assembly

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages