write an assembly language program to print a message

advertisement
Submitted To
Submitted By
1
Serial
No.
01.
02.
03.
04.
05.
06.
07.
08.
09.
Particular
Write an assembly language program to
print a message.
Write an assembly language program to
perform 1 byte BCD addition operation.
Write an assembly language program to
check whether given number is even or odd.
Write an assembly language program to add
two array and store in third array.
Write an assembly language program to find
the average of five different bit number.
Write an assembly language program to
solve the equation z=x^3+y^2+1
Write an assembly language program to
solve the equation x=A*B+(C/D)-E
Write an assembly language program to add
two 8 bit numbers.
Write an assembly language program to
multiply two 16 bit numbers.
Page No.
04
05-06
06
07
08
9
10-11
12
13
2
10.
Write an assembly language program to
exchange two 16 bits numbers.
14
15
11.
Write an assembly language program to
print capital A-Z.
16
12.
Write an assembly language program to
print bubble sort in ascending order.
Write an assembly language program to
convert the temperature from Fahrenheit to
Celsius.
Write an assembly language program to find
out the multiplication of two 3*3 matrixes
and store the result in third array.
Write an assembly language program that
perform BCD operation for subtraction and
also perform multiplication of given
operand.
17
13.
14.
15.
18-19
20-21
3
1. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO PRINT A
MESSAGE
DATA SEGMENT
;START DATA SENMENT
MSG DB 0DH, 0AH,"HI DEAR HOW ARE YOU$"
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX, DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV AH, 09H
; DISPLAY ON DOS PROMPT
MOV DX, OFFSET MSG ; CHARACTER ONE BY ONE READ
INT
21H
; INTTERUPT WHEN CPU BUSY
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
4
2.
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO CHECK
WHETHER GIVEN NUMBER IS ODD OR EVEN.
DATA SEGMENT
; START DATA SEGMENT
MSG1 DB 0DH, 0AH, "IT'S AN EVEN NO. $"
MSG2 DB 0DH, 0AH, "IT'S AN ODD NO. $"
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX, DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV BL, 02
; MOV 02 IN BL REGESTER
MOV AX, 59
; MOV 59 IN AX REGESTER
DIV BL
; PERFORM DIVISION OPRA.
CMP AH, 00H ; COMP WITH REMEDER IS 00
JZ
EVEN
; JUMP ZERO
JNZ ODD
; JUMP NOT ZERO
EVEN:
; LEBEL
MOV DX, OFFSET MSG1 ;READ CHARACTER ONE BY ONE
JMP FINAL
; GOTO FINAL LABEL
ODD:
; LEVEL
MOV DX, OFFSET MSG2 ; READ CHARACTER ONE BY ONE
JMP FINAL
; GOTO LEVEL FINAL
FINAL:
; LEVEL
MOV AH, 09H ;
INT
21H
; INTTERUPT WHEN CPU BUSY
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
5
3.
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO
PERFORM ONE BYTE BCD ADDITION OPERATION.
DATA SEGMENT
; START DATA SEGMENT
OPR1 EQU 72
; STORE NUMBER
OPR2 EQU 35
; STORE NUMBER
SUM DW 01 DUP(00) ; NUMDER OF VARIABLE
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX,DATA
; INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV BL, OPR2 ;MOVE VALUE OF OPR2 INTO BL REG
XOR AL, AL
;INITIALIZED ZERO INTO AL
MOV AL,OPR1
; MOVE VALUE OF OPR1 IN AL REG.
ADD AL,BL
;ADDITION OF OPR1 AND OPR2
;RESULT STORE INTO AL REG
MOV BYTE PTR SUM,AL ; MOV AL VALUE INTO SUM
; FOR DISPLAY
CODE ENDS
END START
; END CODE SEGMENT
OUTPUT
6
4 . WRITE AN ASSEMBLY LANGUAGE PROGRAM TO ADD
ELEMENT OF TWO ARRAY AND STORE THE RESULT IN
THIRD ARRAY
DATA SEGMENT
; START DATA SEGMENT
ARR1 DB 2, 3, 4, 1, 5 ; DEFINE BYTE VARIABLE
ARR2 DB 1, 2, 1, 3, 2 ; DEFINE BYTE VARIABLE
ARR3 DB 05 DUP (?)
; DEFINE BYTE VARIABLE
COUNT EQU 05
; STORE NUMBER
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
BEG:
MOV AX, DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
LEA SI, ARR1
; SET OFFSET ADDRESS OF ARR1
LEA BX, ARR2
; SET OFFSET ADDRESS OF ARR2
LEA DI, ARR3
; SET OFFSET ADDRESS OF ARR3
MOV CL, COUNT ; STORE VALUE OF COUNT IN CL REG.
HITESH:
; LEVEL
MOV AL, [SI]
; MOVE VALUE OF [SI] IN AL
ADD AL, [BX]
; ADD VALUE AL BX REGISTER WITH AL
MOV [DI], AL
; MOVE VALUE OF AL AT ADDRESS DI
INC SI
; INCREMENT SI ARRAY POINTER
INC BX
; INCREMENT BX ARRAY POINTER
INC DI
; INCREMENT DI ARRAY POINTER
DEC CL
; DECEREMENT COUNTER VALUE
JNZ HITESH
; GOTO AT HITESH
CODE ENDS
; END CODE SEGMENT
END BEG
OUTPUT :-
7
5.
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO FIND
AVERAGE OF 5 DIFFERENT 8 BIT NUMBERS.
DATA SEGMENT
; START DATA SEGMENT
SUM DB 01 DUP(?) ; A BYTE MEMORY RESERVE
AVG DB 01 DUP (?); A BYTE MEMORY RESERVE
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
ASSUME CS:CODE DS:DATA
START:
MOV AX,DATA
;INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV AX,00
; SET AX AS 00
MOV AL,04
; MOVE 4 IN AL REGISTER
ADD AL,02
; ADD 02 WIHT VALUE OF AL REG.
ADD AL,08
; ADD 08 WIHT VALUE OF AL REG.
ADD AL,03
; ADD 03 WIHT VALUE OF AL REG.
ADD AL,03
; ADD 03 WIHT VALUE OF AL REG.
MOV SUM,AL
; MOVE VALUE OF AL IN SUM
MOV BL,05
; MOVE 5 TO BX REGISTER
DIV BL
; DIVISION PERFORMED
MOV AVG,AL
; RESULT STORED IN AVG
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
8
6. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE
THE EQUATION Z=X^3+Y^2+1
DATA SEGMENT
; START DATA SEGMENT
A EQU
; A NUMBER STORE
B EQU 03
; A NUMBER STORE
X DB 02
; DEFINE DATA BYTE VARIABLE
Y DB 03
; DEFINE DATA BYTE VARIABLE
Z DB 01 DUP(?) ; A BYTE MEMORY RESERVE
COUNT EQU 02 ; INITILIZE COUNTER
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX,DATA
; DATA SEGMENT INITILIZE REGISTER
MOV DS,AX
MOV CL,COUNT ;MOVE COUNT VALUE INTO CL REG
MOV AL,X
;MOVE X VALUE INTO AL REGISTER
LABEL:
; LEVEL
MUL X
;MULTIPLY X INTO AL REGISTER UNTIL COUNT 0
DEC CL
; DECREMENT CL
JNZ LABEL
; IF JNZ IS TRUE THEN JUMP LABLE
MOV X,AL
; MOVE VALUE OF AL INTO X
MOV BL,AL
; MOVE VALUE OF AL INTO BL
MOV AL,Y
; MOVE Y INTO AL
MUL Y
; MULTIPLY Y INTO AL AND RESULT STORE IN AL
MOV Y,AL
; MOVE VALUE AL INTO Y
MOV DL,A
; MOVE VALUE OF A IN DL REGISTER
MOV X,DL
; MOVE VALUE OF DL IN X
MOV DL,B
; MOVE VALUE OF B IN DL REGISTER
MOV Y,DL
; MOVE VALUE OF DL IN Y
ADD AL,BL
; ADD VALUE OF AL WITH VALUE OF BL
ADD AL,01
; ADD VALUE OF AL WITH 01
MOV Z,AL
; STORE RESULT
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
9
7. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE
THE EQUATION Z=A*B+(C/D)-E.
DATA SEGMENT
;DATA SEGMENT START
A DB 2
;DEFINE BYTE VARIABLE
B DB 4
;DEFINE BYTE VARIABLE
C DB 6
;DEFINE BYTE VARIABLE
D DB 3
;DEFINE BYTE VARIABLE
E DB 1
;DEFINE BYTE VARIABLE
M EQU 4
Y EQU 01
; A NUMBER STORE
K EQU 01
; A NUMBER STORE
Z EQU 01
; A NUMBER STORE
X DB 01 DUP(?) ;A WORD OF MEMORY RES
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX,DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV AX,00
; SET 00 IN AX
MOV AL,C ; MOVE VALUE OF C IN AL REGISTER
DIV D
;DIV OF AL FROM D AND STORE RESULT IN AL REG
MOV DL,AL ; MOVE VALUE OF AL IN DL REGISTERS
MOV AL,A ;MOVING OPERATION PERFORM FOR AL REGISTER
MUL B ;MUL BETWEEN AL AND B STORE RESULT IN AL REG
ADD DL,AL ;ADDITION OF BL AND Z, RESULT STORE IN BL REG
SUB DL,E ;SUB OF DL FROM E, RESULT STORE IN DL REG.
MOV X,DL ;RESULT STORE IN X
CODE ENDS ; END CODE SEGMENT
END START
10
OUTPUT
11
8. WRITE AN ASSEMBLY LANGUAGE PROGRAN TO ADD 8
BIT NUMBERS.
DATA SEGMENT
; START DATA SEGMENT
OPR1 DB 32
; A BIT VARIABLE DECLARE
OPR2 DB 24
; A BIT VARIABLE DECLARE
RES DB 01 DUP(?) ; A BYTE MEMORY RESERVE
DATA ENDS
; END DATA SEGMENT
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX,DATA
; INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV AL,OPR1
;MOVE VALUE INTO AL REGISTER
ADD AL,OPR2
; ADD VALUE OF AL REGISTER AND OPR2
MOV RES,AL
; STORE RESULT INTO RES
CODE ENDS
; END DATA SEGMENT
END START
OUTPUT
12
9. WRITE AN ASSEMBLY LANGUAGE PROGRAN TO ADD 16
BIT NUMBERS.
DATA SEGMENT
; START DATA SEGMENT
OPR1 DW 3221
; A WORD VARIABLES DECLARE
OPR2 DW 2421
; A WORD VARIABLES DECLARE
RESULT DW 01 DUP(?) ; A WORD MEMORY RESERVE
DATA ENDS
; END DATA SEGMENT
ASSUME CS:CODE,DS:DATA
CODE SEGMENT
; STRAT CODE SEGMENT
START:
MOV AX,DATA
; INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV AX,OPR1
;MOVE VALUE INTO AL REGISTER
ADD AX,OPR2
;ADD VALUE OF AL REGISTER AND OPR2
MOV RESULT,AX ;STORE RESULT INTO RESULT
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
13
10
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO
EXCHANGE TWO 16 BIT NUMBER.
DATA SEGMENT
; START DATA SEGMENT
V1 DW 546
; A 16 BIT VARIABLE DECLARE
V2 DW 764
; A 16 BIT VARIABLE DECLARE
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX, DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV DX, V1
; VALUE OF V1 IS MOVING INTO DX REG.
MOV BX, V2
; VALUE OF V2 IS MOVING INTO BX REG.
XCHG DX, BX ; EXCHANGE OPERATION PERFORM
MOV V1,DX
; MOVE VALUE OF BX IN V1
MOV V2,BX
; MOVE VALUE OF BX IN V2
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
14
11. AN ASSEMBLY LANGUAGE PROGRAM TO PRINT CAPITAL A-Z
CODE SEGMENT
; START DATA SEGMENT
START:
MOV [SI],'A' ;CHARACTER START FROM A TO Z(26)
MOV CL, 26 ; MOVE 26 IN CL REGISTER
GO:
; LEVEL
MOV AL,[SI] ;MOV VALUE AT ADDRESS INTO AL REG.
MOV AH,14
INT 10H
; INTTERUPT WHEN CPU BUSY
INC [SI]
; INCREASE VALUE OF SI BY 1
LOOP GO
; GOTO AT GO LEVEL
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
15
12.
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO
PERFORM BUBBLE SORT IN ASSCENDING ORDER.
DATA SEGMENT
; START DATA SEGMENT
LIST DB 67, 45, 55, 42, 88, 76, 33, 80, 22, 10 ; DEFINE BYTE
; VARIABLE
COUNT EQU 10
; A NUMBER STORE
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX, DATA ; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV DL, COUNT-1
; SET GRATER NO AT LAST
AGAIN0:
; LEVEL
MOV CL, DL
; MOVE VALUE OF DL IN CL REG.
LEA SI, LIST ; MOVE VALUE OF LIST IN SI REGISTER
AGAIN1:
; LEVEL
MOV AL, [SI]
; MOVE VALUE AT SI ADDRESS IN AL
CMP AL, [SI+1] ; COMP. NEXT VALUE WITH NEXT VALUE
JL PR1
; JL= JUMP LOWER
XCHG [SI+1], AL ; EXCHVALUE OF AL IN NEXT POSSION IN ARR
XCHG [SI], AL ;EXCH VALUE OF AL IN FIRST POSSION IN ARR
PR1:
; LEVEL
INC SI
; INCREASE ARRAY POINTER
LOOP AGAIN1 ; GO TO LEVEL AT AGAIN1
DEC DL
; DECREASE VALUE OF COUNTER
JNZ AGAIN0
; JUMP NOT ZERO
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
16
13.
WRITE AN ASSEMBLY LANGUAGE PROGRAM TO CONVERT
TEMPARATURE FROM FAHRENHEIT TO CELSIUS
DATA SEGMENT
TEMP_FAH DB 96
; START DATA SEGMENT
; DEFINE BYTE VARIABLE FOR
; FAHRENHEIT.
CELSIUS DB 01 (?) ; A BYET MEMORY RESERVE FOR CELSIUS
ENDS DATA
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
; convert Fahrenheit to Celsius A/C to this formula: c = (f - 32) * 5 / 9
MOV AX, DATA
MOV DS, AX
MOV CL, TEMP_FAH
SUB CL, 32
MOV AL, 5
IMUL CL
MOV CL, 9
IDIV CL
MOV CELSIUS, AL
CODE ENDS
END START
; INITILIZE DATA SEGMENT REGISTER
; MOVE VALUE OF TEMP_FAH IN CL REG.
; SUBTRACT VALUE OF CL REG. WITH 32.
; MOVE 5 IN AL REGISTER.
; MULTIPLICATION OPERATION PERFORM
; MOVE 9 IN CL REGISTER
; DIVISION OPERATION PERFORM
; MOVE VALUE OF AL REGISTER IN CELSIUS
; END CODE SEGMENT
OUTPUT
17
14.
WRITE AN ASSEMBLY LANGUAGE PROGRAM THAT PERFORM
BCD OPERATION FOR SUBTRACTION AND ALSO PERFORMS
MULTIPLICATION GIVEN OPERATOR
DATA SEGMENT
; START DATA SEGMENT
OPR1 EQU 72
; DEFINE BYTE VARIABLE
OPR2 EQU 35
; DEFINE BYTE VARIABLE
SUM DW 01 DUP(00) ; A WORD MEMORY RESERVE FOR SUM
SUBT DW 01 DUP(00) ; A WORD MEMORY RESERVE FOR SUB
MULT DW 01 DUP(00) ; A WORD MEMORY RESERVE FOR DIV
DIVS DW 01 DUP(00)
DATA ENDS
; END DATA SEGMENT
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX, DATA
; INITILIZE DATA SEGMENT REGISTER
MOV DS, AX
MOV BL, OPR2
; MOVE VALUE OF OPR2 INTO BL REGISTER
XOR AL, AL
; INITIALIZED ZERO INTO AL
MOV AL, OPR1
ADD AL, BL
; ADDITION OF OPR1 AND OPR2 RESULT
; STORE INTO AL REGISTER
MOV BYTE PTR SUM,AL,; MOV AL VALUE INTO SUM FOR
; DISPLAY
JNC MSB0
; JUMP MSB0;
INC [SUM+1]
; INCREMENT VALUE OF SUM
MSB0:
; LEVEL
XOR AL,AL
; INITILIZATION BY 0 IN AL REGISTER
MOV AL,OPR1
; MOVE VALUE OF OPR1 IN AL REGISTER
SUB AL,BL
;SUBTRACTION OF OPR1 AND OPR2
; RESULT STORE INTO AL REGISTER
DAS
MOV BYTE PTR SUBT,AL
JNB MSB1
; JUMP TO MSB1 LEVEL
MSB1:
; LEVEL
XOR AX,AX
; INITILIZATION BY 0 IN AX REGISTER
MOV AL,OPR1
; MOVE VALUE OF OPR1 IN AL REG.
MUL BL
; MULTIPLICATION OF OPR1 AND OPR2
; RESULT STORE INTO AL REGISTER
MOV WORD PTR MULT,AX
XOR AX,AX
; INITILIZATION BY 0 IN AX REGISTER
MOV AL,OPR1
; MOVE VALUE OF OPR1 IN AL REG.
18
DIV BL
;DIVISION OF OPR1 AND OPR2 RESULT STORE
; INTO AL REGISTER
MOV BYTE PTR DIVS,AL
; MOVE VALUE OF AL AT ADDRESS OF
; DIVS
CODE ENDS
; END CODE SEGMENT
END START
OUTPUT
19
15. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO
MULTIPLICATION OF 3*3 MATRIX.
DATA SEGMENT
; START DATA SEGMENT
ROWCOL EQU 03H
; STORE NUMBERS FOR COUNTER
MAT1 DB 1,2,3,4,5,6,7,8,9 ; BYTE VARIABLE DECLARATION
MAT2 DB 3,4,2,6,3,1,4,5,2 ; BYTE VARIABLE DECLARATION
PMAT DW 09 DUP(?)
; A WORD MEMORY RESERVE
DATA ENDS
; END DATA SEGMENTS
CODE SEGMENT
; START CODE SEGMENT
START:
MOV AX,DATA
; INITILIZE DATA SEGMENT REGISTER
MOV DS,AX
MOV CH,ROWCOL ;STORE ROWCALL VALUE INTO CH REGISTER
MOV BX,OFFSET PMAT;MOVE OFFSET ADDRESS OF PMAT INTO BX
;REGISTER
MOV SI,OFFSET MAT1;MOVE OFFSET ADDRESS OF PMAT INTO SI
;REGISTER
NEXTROW:
;LABEL
MOV DL,OFFSET MAT2;SO ON LIKE ABOPVE LINE
MOV CL,ROWCOL ;FOR COUNTER THREE TIMES
NEXTCOL:
;LABEL
MOV DL,ROWCOL ;EQUIT VALUE STORE INTO THE DL REGISTER
MOV BP,0000H ;ADDRES STORE START FROM 0
MOV AX,0000H ;INITIALIZED WITH 0 OF AX REGISTER
NEXT-ELE:
MOV AL,[SI] ;MOVE VALUE AT ADDRESS OF ST REG. INTO THE
;AL REGISTER
MUL BYTE PTR[DI] ;MLTIPLY BETWEEN VALUE OF DI AND AL REG.
ADD BP,AX ;ADITION OF AX AND BP REGISTER
INC SI ;INCREMENT SI
ADD DI,03
; ADD DI WITH 03
DEC DL
;DECREMENT DL
JNZ NEXT-ELE ;JUMP IN LABEL
SUB DI,08
; SUBTRACT VALUE OF DI WITH 08
SUB SI,03
; SUBTRACT VALUE OF SI WITH 03
MOV [BX],BP
; MOVE VALUE OF BP AT ADDRESS OF BX
ADD BX,02
; ADD BX WITH 02
DEC CL
; DECREMENT CL
JNZ NEXTCOL
; JUMP UNTILL CL 0
20
ADD SI,03
DEC CH
JNZ NEXTROW
CODE ENDS
END START
; ADD VALUE OF SI WITH 03
;DECREMENT CH REGISTER
;JUMP UNTILL C 0
; END CODE SEGMENT
OUTPUT
21
Download