You are on page 1of 38

Tutorial Problems Set 1 (8085 based) 1.

Write an 8085 program to add ten numbers stored in consecutive memory address starting from 8067H and store the sixteen bit result at the end of the table. 2. Write an 8085 program to add ten numbers stored in the consecutive memory locations starting from 8081H and display the result in the two output ports. (you can assume any address for the port) 3. Add all the positive numbers stored in the memory location 80A1H to 80AAH. Display the 16-bit result in any ports. 4. Add all the numbers with bit D5 and D3, 1 and 0 respectively, stored in the memory location 90B1H to 90BAH. Display the 16-bit result in any ports. 5. There are two table of data stored at 80A1H and 80B1H having ten data each. Write a program to store the data in the first table to third table starting from address 80C1H if the corresponding data in the first table is greater than the second table else store FFH in the third table. 6. Sixteen bit data are stored in two tables starting at 8050H and 8070H, ten data in each table. Add corresponding data and store it in the third table starting at 8090H. (Never forget the reverse order convention in storing the 16-bit data) 7. Add sixteen bit data stored in two tables and store the result in the corresponding index of the third table if the result in the corresponding index of the third table only if the result is greater than 00FFH, else store 0000H (you can assume any address for the tables) 8. In two tables 16-bit data are stored, each table having ten numbers each. Subtract the data from one table to other and store the result in the third table. 9. Subtract ten 16-bit data stored in one table from the other. Store the result in the third table if the result is positive else store 00. 10. Transfer ten data, which has bit D5 and D0, 0 and 1 respectively from A430H to A440H, else store 00 instead of transformation. 11. Transfer ten data with even parity from location 9270H to 9280H, else transfer the data by clearing bit D7 and setting bit D2. 12. Data is stored from 8040H to 8050H. Transfer the data to other location in reverse order. 13. Add ten 16-bit numbers stored in a table at 9500H and store the 24-bit result at the end of the table. 14. Data is stored from 8050H to 805AH. Insert 5 data after 8055H taking from 8040H,

but do not lose the previous content. 15. Ten data are stored from 8080H. Transfer the first 5 numbers at the end of the second table and the rest at the starting of it. 16. Transfer data from 9050H to 9060H only if data is between 30H and 70H else store 00H in the next table. 17. Transfer data from 8250H to 8260H if the number is less than 50H and greater than 80H else store 00H in the destination table. 18. Write a program to count the number of ones of table of ten sixteen bit numbers at 8240H and store the count of ones in corresponding location of a table at 8260H 19. Write a program to convert binary numbers stored in a table at 8560h to BCD numbers and store the result in the second table at 8570H. Assume no number is greater than 63H (99D). 20. Write a program to convert ten BCD numbers stored at 8350H to binary and store the result at 8360H. 21. Ten data are stored in memory location starting at 8345H. Write a program to convert binary number to BCD number and store the result in the second table in the memory location starting at 8445H if the result is less than hundred.

Tutorial Problems Set 2 (8086 based) 1. Write an assembly language program to add all the elements of a table, which are between 50 and 150 only. Display the result as the decimal value. 2. A table of numbers is stored in memory. Write an assembly language program to add numbers from the table, which are between 30 and 100. Display the result in hex format. 3. Write an assembly language program to get text input and display it on the center of a clear screen. 4. Write an assembly language program to accept string input and convert to upper case if it has lower case letters. 5. Write an assembly language program to get input and display on location 10,20 on the screen 6. Write an assembly language program to convert the text stored in memory to upper case only if the characters are found in lower case. Display the converted text in the screen.

7. Write an assembly language program to convert the text stored in the memory to lower case if the characters are in upper case. Display the result text in the screen 8. Write a program to add the sequence 1+3-+-4+... up to 100 steps display the result in hexadecimal format. 9. Write a program to add the sequence 1+3+4+... up to the desired steps entered by the user and display the result in decimal format. Assume user enters numbers from 1 to 9. 10. Write an assembly language program to display graphical ASCII characters from 32 to 127 on a defined window (5,10 and 20,70) with white on blue attribute. 11. You have an array of data in one table. Change each element to decimal ASCII and store it in the next table. Display the final result in the clear screen. 12. Write an assembly language program to count the number of vowels in a string entered by the user. Display the result in decimal format. 13. Write an assembly language program to convert the vowels to uppercase from a string entered by the user. 14. Write an assembly language program to get string input from the user convert it to capital case display the attributed string at the center of the defined window (2,10 to 22,70). 15. Write an assembly language program to get string input from the user convert it to lower case display the attributed string at the lower left comer of the defined window (3,10 to 21,10). 16. Write an assembly language program that takes a string input from user and clear the screen and move the string from right edge of the screen to left edge. The movement should be noticeable. 17. Write an assembly language program to generate a multiplication table of any number entered by the user. Display the table in the screen.

7.1TITLE to dispay string using string display function


.MODEL SMALL .STACK 32 .DATA STRING DB "Programming is Fun",0DH,0AH,'$' .CODE MAIN PROC FAR

MOV AX,@DATA MOV DS,AX LEA DX,STRING MOV AX,0900H INT 21H MOV AX,4C00H INT 21H MAIN ENDP END MAIN

72TITLE to dispay string using character display function


.MODEL SMALL .STACK 32 .DATA STRING DB "Programming is Fun" LEN DW $-STRING .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV CX,LEN MOV SI,0 L:MOV DL,STRING[SI] MOV AH,02H INT 21H INC SI LOOP L MOV AX,4C00H INT 21H MAIN ENDP END MAIN

73 TITLE to read and display string using string display and read function
.MODEL SMALL .STACK 32 .DATA STRING DB 22 DUP(?)

ENTER DB 0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV STRING,20 MOV AH,0AH LEA DX,STRING INT 21H LEA DX,ENTER MOV AX,0900H INT 21H LEA DX,STRING+2 MOV AX,0900H INT 21H MOV AX,4C00H INT 21H MAIN ENDP END MAIN

74TITLE to read and display string using character


.MODEL SMALL .STACK 32 .DATA NEWLINE DB 0DH,0AH,'$' STRING DB 15 DUP(?) LEN DW ? .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV AH,01H MOV CX,15 MOV BX,00H L: INT 21H MOV STRING[BX],AL INC BX

CMP AL,0DH LOOPNE L LEA DX,NEWLINE MOV AX,0900H INT 21H MOV LEN,BX MOV AH,02H MOV CX,LEN MOV BX,00H L1:MOV DL,STRING[BX] INT 21H INC BX LOOP L1 MOV AX,4C00H INT 21H MAIN ENDP END MAIN

7.5TITLE to convert to uppercase


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 15 ACTCHAR DB ? STRING DB 14 DUP(?) NSTRING DB 15 DUP('$') NEWLINE DB 0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H LEA DX,NEWLINE MOV AH,09H INT 21H

MOV CL,ACTCHAR MOV BX,00H L:MOV AL,STRING[BX] CMP AL,97D JNGE BREAK SUB AL,32D BREAK:MOV NSTRING[BX],AL INC BX LOOP L LEA DX,NSTRING MOV AH,09H INT 21H MOV AX,4C00H INT 21H MAIN ENDP END MAIN

TITLE to display each word in seprate lin


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 15 ACTCHAR DB ? STRING DB 15 DUP(?) NEWLINE DB 0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX MOV AH,0AH LEA DX,MAXCHAR INT 21H MOV AH,09H LEA DX,NEWLINE INT 21H MOV BX,00H L:CMP ACTCHAR,BL

JNG EXIT MOV DL,STRING[BX] MOV AH,02H INT 21H INC BX CMP DL,' ' JNE L MOV AH,09H LEA DX,NEWLINE INT 21H JMP L EXIT:MOV AX,4C00H INT 21H MAIN ENDP END MAIN OUTPUTl: MY NAME MY NAME

TITLE TO WHETHER THE ENTERED STRING IS PALINDROME OR NOT


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? STR DB 30 DUP('?') NEWLINE DB 0DH,0AH,'$' PALIN DB "palindrome",0DH,0AH,'$' NOPALIN DB "no palindrome",0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR;INPUT STRING MOV AH,0AH INT 21H MOV AL,ACTCHAR;NO OF CHARACTERS MOV AH,00 MOV BL,02

MOV BH,00 DIV BL;;CALCULATE HALF LENGTH MOV CL,AL MOV CH,00 MOV AL,ACTCHAR MOV AH,00 SUB AL,1;ARR STARTS FROM 0 i.e. IF LENGTH IS 5,CHARACTERS ARE ARR[0]-ARR[4] MOV SI,AX;FOR LAST CHARACTER MOV BX,00;FOR FIRST CHARACTER L: MOV AL,STR[SI];LAST CHARACTER CMP AL,STR[BX];COMPARE RESPECTIVE FIRST AND LAST DATA JE L1 LEA DX,NEWLINE;DISPLAY NEWLINE MOV AH,09H INT 21H LEA DX,NOPALIN;DISPLAY NOT PALINDROME MOV AH,09H INT 21H JMP L2 L1:DEC SI;PREVIOUS FROM LAST INC BX;NEXT FROM FIRST LOOP L LEA DX,NEWLINE;DISPLAY NEWLINE MOV AH,09H INT 21H LEA DX,PALIN;DISPLAY PALINDROME MOV AH,09H INT 21H L2:MOV AX,4C00H INT 21H MAIN ENDP END MAIN

8.1TITLE to display string in defined window


.MODEL SMALL .STACK 32 .DATA STR DB "Programming in Assembly Language is Fun",'$' LEN DB 39 .CODE MAIN PROC FAR MOV AX,@DATA

MOV

DS,AX

MOV AH,00H MOV AL,03H INT 10H MOV AH,08H MOV BH,00 INT 10H MOV CL,4 ROL AH,CL ; MOV BH,AH MOV AH,07H MOV AL,00 MOV CH,5 MOV CL,20 MOV DH,20 MOV DL,60 INT 10H MOV CX,1 MOV BL,LEN MOV SI,0 MOV DL,30 MOV DH,12 MOV BH,00 MOV AH,02H INT 10H

L:

MOV AL,STR[SI] MOV AH,0AH INT 10H INC DL CMP DL,50 JL L1 CMP STR[SI],' ' JNE L1 INC DH MOV DL,30 L1: INC SI

DEC BL CMP BL,0 JG L MOV AX,4C00H INT 21H MAIN ENDP END MAIN

8.2TITLE to display user input string at the center of the clear screen
.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 60 ACTCHAR DB ? STR DB 60 DUP('$') .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV AH,00H MOV AL,03H INT 10H MOV AL,ACTCHAR MOV CH,2 DIV CH MOV MOV SUB MOV MOV MOV MOV MOV DH,12 DL,40 DL,AL BL,ACTCHAR CX,1 SI,0 AH,02H BH,00

L:

INT

10H

MOV AL,STR[SI] MOV AH,0AH INT 10H INC SI INC DL DEC BL CMP BL,0 JG L MOV AH,4CH INT 21H MAIN ENDP END MAIN Output: sentiking Setniking

8.3TITLE to display each character of the user input string at center


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 24 ACTCHAR DB ? STR DB 24 DUP('$') .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV AH,00H MOV AL,03H INT 10H MOV MOV MOV MOV DH,0 DL,40 CX,1 SI,0

L:

MOV BL,ACTCHAR MOV AH,02H MOV BH,00 INT 10H MOV AL,STR[SI] MOV AH,0AH INT 10H INC SI INC DH DEC BL CMP BL,0 JG L

MOV AH,4CH INT 21H MAIN ENDP END MAIN

8.4TITLE to display user input string at ghe center of scrolled window


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 14 ACTCHAR DB ? STR DB 14 DUP('$') .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV AH,00H MOV AL,03H INT 10H MOV MOV AH,07H AL,00

MOV CH,2 MOV CL,30 MOV DH,22 MOV DL,50 MOV BH,70H INT 10H MOV AH,0 MOV AL,ACTCHAR MOV CH,2 DIV CH MOV DH,12 MOV DL,40 SUB DL,AL MOV BL,ACTCHAR MOV CX,1 MOV SI,0 MOV AH,02H MOV BH,00 INT 10H MOV AL,STR[SI] MOV AH,0AH INT 10H INC SI INC DL DEC BL CMP BL,0 JG L MOV AH,4CH INT 21H MAIN ENDP END MAIN

L:

TITLE to display each word diagonally


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 60 ACTCHAR DB ?

STR

DB 60 DUP('$') .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV AH,00H MOV AL,03H INT 10H MOV DH,0 MOV DL,0 MOV BL,ACTCHAR MOV CX,1 MOV SI,0 MOV AH,02H MOV BH,00 INT 10H

L:

MOV AL,STR[SI] MOV AH,0AH INT 10H CMP STR[SI],' ' JNE L1 DEC DL INC DH L1: INC SI INC DL DEC BL CMP BL,0 JG L MOV AH,4CH INT 21H MAIN ENDP END MAIN

9.1

TITLE to find sum 1-N in decimal

.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? INPUT DB 30 DUP('?') N DW 0 NEWLINE DB 0DH,0AH,'$' SUM DW ? .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,0 MOV SI,0 ;Read characters for a number and add with prev num L1: MOV AL,INPUT[SI] CMP SI,CX ;Stop if the user presses return JE L2 SUB AL,30H ;convert the digit to ASCII MOV AH,0 PUSH AX ;Save the digit for further purpose MOV AX,10 ;Multiply NUM by ten and store it back MUL N ;As we are using byte operation the result MOV N,AX ;will not be greater than byte POP AX ;recover back the number ADD N,AX ;Add it with the previous result INC SI JMP L1 L2: MOV CX,N MOV AX,0 L3: ADD AX,CX LOOP L3

;add 1-N

MOV

SUM,AX

LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display MOV CX,10 MOV AX,SUM MOV BX,0 ;Find each decimal digit of the number and store in stack MOV DX,0 DIV CX ;Divide by 10 ADD DX,30H ;Convert the digit to characters PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4

L4:

;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.2 TITLE to find sum 2*4+3*6 .... to N terms in decimal


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? INPUT DB 30 DUP('?') N DW 0 NEWLINE DB 0DH,0AH,'$' SUM DW ?

.CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,0 MOV SI,0 ;Read characters for a number and add with prev num L1: MOV AL,INPUT[SI] CMP SI,CX ;Stop if the user presses return JE L2 SUB AL,30H ;convert the digit to ASCII MOV AH,0 PUSH AX ;Save the digit for further purpose MOV AX,10 ;Multiply NUM by ten and store it back MUL N ;As we are using byte operation the result MOV N,AX ;will not be greater than byte POP AX ;recover back the number ADD N,AX ;Add it with the previous result INC SI JMP L1 L2: MOV CX,N MOV BX,2 L3: MOV AX,BX ADD AX,AX MUL BX ADD SUM,AX INC BX LOOP L3

;add 1-N

LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display MOV CX,10

MOV MOV

AX,SUM BX,0

;Find each decimal digit of the number and store in stack L4: MOV DX,0 DIV CX ;Divide by 10 ADD DX,30H ;Convert the digit to characters PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4 ;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.3TITLE to count the no of words and display in decimal


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? STR DB 30 DUP('$') NEWLINE DB 0DH,0AH,'$' COUNT DW ? .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H

MOV CL,ACTCHAR MOV CH,0 MOV SI,0 MOV BX,0 L1: CMP STR[SI],' ' JNE L2 MOV DX,BX MOV BX,-1 CMP DX,0 JE L2 ADD COUNT,1 L2: INC SI INC BX LOOP L1 CMP BX,0 JE L3 ADD COUNT,1 L3: LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display MOV CX,10 MOV AX,COUNT MOV BX,0 ;Find each decimal digit of the number and store in stack L4: MOV DX,0 DIV CX ;Divide by 10 ADD DX,30H ;Convert the digit to characters PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4 ;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP

MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.4TITLE to count the no of vowels and display in decimal


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? STR DB 30 DUP('$') VOWELS DB "AEIOUaeiou" NEWLINE DB 0DH,0AH,'$' COUNT DW 0 .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,0 MOV SI,0 L1: MOV AL,VOWELS[DI] CMP AL,STR[SI] JNE L2 ADD COUNT,1 INC SI MOV DI,0 JMP L1 L2: INC DI CMP DI,10 JNE L1 MOV DI,0 INC SI LOOP L1

L3:

LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display MOV CX,10 MOV AX,COUNT MOV BX,0

;Find each decimal digit of the number and store in stack L4: MOV DX,0 DIV CX ;Divide by 10 ADD DX,30H ;Convert the digit to characters PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4 ;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.5TITLE to add ten 16-bit numbers stored in memory and store and display in decimal
.MODEL SMALL .STACK 32 .DATA TABLE DW 257,258,259,260,261,262,263,264,265,266 SUM DW ? NEWLINE DB 0DH,0AH,'$' .CODE MAIN PROC FAR MOV AX,@DATA

MOV MOV MOV MOV L1: ADD ADD LOOP MOV

DS,AX CX,10 AX,0 SI,0 AX,TABLE[SI] SI,2 L1 SUM,AX

;back to ascii format for display MOV CX,10 MOV AX,SUM MOV BX,0 ;Find each decimal digit of the number and store in stack L2: MOV DX,0 DIV CX ;Divide by 10 ADD DX,30H ;Convert the digit to characters PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L2 ;Get characters from stack and display as decimal number MOV AH,02H MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.6TITLE to find sum 1-N in hexadecimal


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ?

INPUT DB 30 DUP('?') N DW 0 NEWLINE DB 0DH,0AH,'$' SUM DW ? .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,0 MOV SI,0 ;Read characters for a number and add with prev num L1: MOV AL,INPUT[SI] CMP SI,CX ;Stop if the user presses return JE L2 SUB AL,30H ;convert the digit to ASCII MOV AH,0 PUSH AX ;Save the digit for further purpose MOV AX,10 ;Multiply NUM by ten and store it back MUL N ;As we are using byte operation the result MOV N,AX ;will not be greater than byte POP AX ;recover back the number ADD N,AX ;Add it with the previous result INC SI JMP L1 L2: MOV MOV L3: ADD LOOP MOV CX,N AX,0 AX,CX ;add 1-N L3 SUM,AX

LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display

MOV MOV MOV

CX,16 AX,SUM BX,0

;Find each decimal digit of the number and store in stack MOV DX,0 DIV CX ;Divide by 16 CMP DX,10 JGE A41H ADD DX,30H ;Convert the digit to characters JMP CONT A41H: SUB DX,0AH ADD DX,41H ;convert the digit to characters CONT: PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4 L4: ;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN

9.7 TITLE to find sum 2*4+3*6 .... to N terms in hexadecimal


.MODEL SMALL .STACK 32 .DATA MAXCHAR DB 30 ACTCHAR DB ? INPUT DB 30 DUP('?') N DW 0 NEWLINE DB 0DH,0AH,'$' SUM DW ? .CODE MAIN PROC FAR

MOV MOV

AX,@DATA DS,AX

LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,0 MOV SI,0 ;Read characters for a number and add with prev num L1: MOV AL,INPUT[SI] CMP SI,CX ;Stop if the user presses return JE L2 SUB AL,30H ;convert the digit to ASCII MOV AH,0 PUSH AX ;Save the digit for further purpose MOV AX,10 ;Multiply NUM by ten and store it back MUL N ;As we are using byte operation the result MOV N,AX ;will not be greater than byte POP AX ;recover back the number ADD N,AX ;Add it with the previous result INC SI JMP L1 L2: MOV CX,N MOV BX,2 L3: MOV AX,BX ADD AX,AX MUL BX ADD SUM,AX INC BX LOOP L3

;add 1-N

LEA DX,NEWLINE ;insert new line MOV AH,09H INT 21H ;back to ascii format for display MOV CX,16 MOV AX,SUM MOV BX,0

;Find each decimal digit of the number and store in stack L4: MOV DX,0 DIV CX ;Divide by 16 CMP DX,10 JGE A41H ADD DX,30H ;Convert the digit to characters JMP CONT A41H: SUB DX,0AH ADD DX,41H ;convert the digit to characters CONT: PUSH DX ;Store the decimal digit in the stack INC BX CMP AX,0 ;Stop if the number is <= 0 JA L4 ;Get characters from stack and display as decimal number MOV AH,02 MOV CX,BX DISP: POP DX INT 21H ;Display the character LOOP DISP MOV AX, 4C00H INT 21H MAIN ENDP END MAIN Output: 10_ <3F2

Tut1
data segment ARR DB 50H,40H,69H,60H,33H SUM DW 0 ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA

MOV DS,AX MOV CX,05H MOV SI,0 L1:MOV AH,00 MOV AL,ARR[SI] CMP AL,32H JC L CMP AL,96H JNC L ADD SUM,AX MOV AX,SUM L: INC SI LOOP L1 MOV AX,SUM MOV CX,0AH MOV BX,0 L2:MOV DX,00 DIV CX ADD DX,30H PUSH DX INC BX CMP AL,0 JA L2 MOV AH,02 MOV CX,BX D: POP DX INT 21H LOOP D mov ax, 4c00h int 21h ends end start

tut2
data segment ARR DB 50H,40H,69H,60H,33H SUM DW 0 ends

stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX MOV CX,05H MOV SI,0 L1:MOV AH,00 MOV AL,ARR[SI] CMP AL,1EH JC L CMP AL,64H JNC L ADD SUM,AX MOV AX,SUM L: INC SI LOOP L1 MOV AX,SUM MOV CX,16 MOV BX,0 L2:MOV DX,00 DIV CX CMP DX,10 JGE L3 ADD DX,30H JMP C L3:SUB DX,0AH ADD DX,41H C: PUSH DX INC BX CMP AL,0 JA L2 MOV AH,02 MOV CX,BX D: POP DX INT 21H LOOP D

mov ax, 4c00h int 21h ends end start

tutt3
data segment MAXCHAR DB 80 ACTCHAR DB ? STR DB 80 DUP('?') ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H LEA BX,STR MOV CL,ACTCHAR ADD BL,CL MOV AL,'$' MOV [BX],AL MOV AH,00H MOV AL,03H INT 10H MOV BH,0 MOV AH,02H MOV DH,12 MOV DL,40 INT 10H LEA DX,STR MOV AH,09H INT 21H

; add your code here mov ax, 4c00h int 21h ends end start

tut4
data segment STR DB 80 DUP('?') ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX MOV CL,00 LEA BX,STR L1: MOV AH,01H INT 21H CMP AL,0DH JE L2 CMP AL,61H JC L CMP AL,7AH JNC L SUB AL,20H L: MOV [BX],AL INC CL INC BX JMP L1 L2: LEA BX,STR ADD BL,CL

MOV AL,'$' MOV [BX],AL LEA DX,STR MOV AH,09H INT 21H mov ax, 4c00h int 21h ends end start

TUT5
data segment MAXCHAR DB 80 ACTCHAR DB ? STR DB 80 DUP('?') N DW 0 NEWLINE DB 0DH,0AH,'$' ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,00 MOV SI,00 L: MOV AL,STR[SI] CMP SI,CX JE L2 SUB AL,30H MOV AH,00 PUSH AX MOV AX,10

MUL N MOV N,AX POP AX ADD N,AX INC SI JMP L ; add your code here L2: MOV AX,N MOV CX,10 MOV BX,00 L3: MOV DX,00 DIV CX ADD DX,30H PUSH DX INC BX CMP AX,0 JA L3 LEA DX,NEWLINE MOV AH,09H INT 21H MOV AH,02H MOV CX,BX LO: POP DX INT 21H LOOP LO mov ax, 4c00h int 21h ends end start

TUT6
data segment STR DB "PrOGRAmmiNG iS fuN $",0DH,0AH ends stack segment dw 128 dup(0) ends code segment

start: MOV AX,@DATA MOV DS,AX LEA BX,STR MOV SI,0 L: MOV AL,STR[SI] CMP AL,'$' JE L2 CMP AL,97 JC L1 CMP AL,122 JNC L1 SUB AL,32 L1: MOV [BX],AL INC BX INC SI JMP L L2: MOV AH,09H LEA DX,STR INT 21H ; add your code here mov ax, 4c00h int 21h ends end start

TUT7 TUT8
data segment SUM DW 0 ends stack segment dw 128 dup(0) ends code segment start:

MOV AX,@DATA MOV DS,AX MOV CX,64H L1:ADD SUM,CX MOV AX,SUM L: INC AL LOOP L1 MOV AX,SUM MOV CX,16 MOV BX,0 L2:MOV DX,00 DIV CX CMP DX,10 JGE L3 ADD DX,30H JMP C L3:SUB DX,0AH ADD DX,41H C: PUSH DX INC BX CMP AL,0 JA L2 MOV AH,02 MOV CX,BX D: POP DX INT 21H LOOP D mov ax, 4c00h int 21h ends end start

TUT9
data segment MAXCHAR DB 80 ACTCHAR DB ? STR DB 80 DUP('?') N DW 0

SUM DW 0 ANSWER DB 0DH,0AH,"THE SUM IS $" ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX LEA DX,MAXCHAR MOV AH,0AH INT 21H MOV CL,ACTCHAR MOV CH,00 MOV SI,0 L5:MOV AL,STR[SI] CMP SI,CX JE LO SUB AL,30H MOV AH,00 PUSH AX MOV AX,10 MUL N MOV N,AX POP AX ADD N,AX INC SI JMP L5 LO:MOV CX,N L1:ADD SUM,CX MOV AX,SUM LOOP L1 MOV AX,SUM MOV CX,10 MOV BX,0 L2:MOV DX,00 DIV CX ADD DX,30H

PUSH DX INC BX CMP AL,0 JA L2 LEA DX,ANSWER MOV AH,09H INT 21H MOV AH,02 MOV CX,BX D: POP DX INT 21H LOOP D

mov ax, 4c00h int 21h ends end start

TUT10
data segment ends stack segment dw 128 dup(0) ends code segment start: MOV AX,@DATA MOV DS,AX MOV AH,00 MOV AL,03H INT 10H MOV AH,06H MOV AL,0 MOV BH,27

MOV CH,5 MOV CL,10 MOV DH,20 MOV DL,70 INT 10H MOV BH,0 MOV DH,05 MOV DL,20 MOV AH,02H INT 10H MOV AH,08H MOV BH,0 INT 10H MOV BL,AH MOV AL,32 L:MOV AH, 0AH MOV BH, 00H MOV CX, 1 INT 10H MOV AH, 03H MOV BH, 00H INT 10H INC DL CMP DL,70 JC L1 SUB DL,50 INC DH L1: MOV AH,02H INT 10H INC AL CMP AL,127 LOOPNE L mov ax, 4c00h int 21h ends end start

You might also like