Showing posts with label Microprocessor Practical Programs. Show all posts
Showing posts with label Microprocessor Practical Programs. Show all posts

Convert a binary number to ASCII character string.

8).Convert a binary number to ASCII character string.

.MODEL SMALL
.DATA
INPUT DB 10,13 , 'ENTER BINARY NO: $'
OUTPUT DB 10,13, 'THE ASCII CHARACTER IS:$'
ARR DB ?
.CODE
.STARTUP
MOV AH,09H
MOV DX,OFFSET INPUT
INT 21H
MOV BL, 00H
MOV CL,08H
INPUT1: MOV AH,01H
INT 21H
SUB AL,30H
SHL BL,1
ADD BL,AL
LOOP INPUT1
MOV AH,09H
LEA DX,OUTPUT
INT 21H
MOV AH,02H
MOV DL,BL
INT 21H
.EXIT

END

Convert an ASCII coded decimal number into its binary equivalent.

7).Convert an ASCII coded decimal number into its binary equivalent.

.MODEL SMALL
.DATA
MESG DB 10,13, 'ENTER NO: $'
RESULT DB 10,13, 'RESULT IS: $'
.CODE
.STARTUP
MOV DX,OFFSET MESG
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
MOV BL,AL
MOV DX,OFFSET RESULT
MOV AH,09H
0INT 21H
MOV CL,08H
MOV AH,00H
MOV AL,BL
L1: SHL AL, 01H
MOV BL,AL
MOV AL,00H
ADC AL,30H
MOV DL,AL
MOV AH,02H
INT 21H
MOV AL,BL
LOOP L1
.EXIT

END

WAP to add and subtract two arrays.

6).WAP to add and subtract two arrays.

Addition:

.model small
.data
mat1 db 12h, 11h, 12h, 10h, 11h, 12h, 10h, 11h, 12h
mat2 db 13h, 02h, 02h, 02h, 02h, 02h, 02h, 02h, 02h
res3 dw 9 dup(?)
.code                        
     mov   ax, @data      
     mov   ds, ax
     mov   cx, 09h      
     mov   di, offset mat1    
     mov   bx, offset mat2      
     mov   si, offset res3    
back :   mov   ah, 0        
     mov   al, [di]      
     sub   al, [bx]      
     adc   ah, 00        
     mov   [si], ax      
     inc   di        
     inc   bx        
     inc   si        
     inc   si  
     loop   back        
     mov   si, offset res3
     mov   dh, 9  
l10:    mov   ch, 04h      
     mov   cl, 04h      
     mov   bx, [si]      
l2:    rol   bx, cl        
     mov   dl, bl        
     and   dl, 0fh        
     cmp   dl, 09        
     jbe   l4
     add   dl, 07        
l4:    add   dl, 30h
     mov   ah, 02        
     int   21h  
     dec   ch        
     jnz   l2
     mov   dl, ' '    ;ye space h    
     int   21h  
     inc   si        
     inc   si  
     dec   dh        
     jnz   l10  
     mov   ah, 4ch      
     int   21h
   end

Subtraction:

.model small
.data
mat1 db 12h, 11h, 12h, 10h, 11h, 12h, 10h, 11h, 12h
mat2 db 13h, 02h, 02h, 02h, 02h, 02h, 02h, 02h, 02h
res3 dw 9 dup(?)
.code                        
     mov   ax, @data      
     mov   ds, ax
     mov   cx, 09h      
     mov   di, offset mat1    
     mov   bx, offset mat2      
     mov   si, offset res3    
back :   mov   ah, 0        
     mov   al, [di]      
     add   al, [bx]      
     adc   ah, 00        
     mov   [si], ax      
     inc   di        
     inc   bx        
     inc   si        
     inc   si  
     loop   back        
     mov   si, offset res3
     mov   dh, 9  
l10:    mov   ch, 04h      
     mov   cl, 04h      
     mov   bx, [si]      
l2:    rol   bx, cl        
     mov   dl, bl        
     and   dl, 0fh        
     cmp   dl, 09        
     jbe   l4
     add   dl, 07        
l4:    add   dl, 30h
     mov   ah, 02        
     int   21h  
     dec   ch        
     jnz   l2
     mov   dl, ' '    ;ye space h    
     int   21h  
     inc   si        
     inc   si  
     dec   dh       
     jnz   l10  
     mov   ah, 4ch      
     int   21h

   end

Write an assembly language program to sort a list.

5).Write an assembly language program to sort a list.

.model small
.386
.data
ARRAY DW 20 DUP (?)
DATA1 dw 0000H
msg db 10,13,"Enter the size of the array :: $"
msg2 db 10,13,"Enter the array :: $"
msg3 db 10,13,"The sorted array is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV AH,01
INT 21H
SUB AL,30H
MOV AH,0
MOV CX,AX
MOV DATA1,AX
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV AH,0
MOV SI, 0
MOV BX, OFFSET ARRAY
L1: MOV DL, 0AH ; jump onto next line
MOV AH, 02H
INT 21H
MOV DX, SI ; input element of the array
MOV AH, 01H
INT 21H
SUB AL,30H
MOV SI, DX
MOV [BX + SI], AX
INC SI
LOOP L1
MOV CX, DATA1
MOV BX, OFFSET ARRAY
MOV DI,CX
L2: MOV CX, DATA1
MOV SI, 0
L3: MOV AL, [BX + SI]
CMP AL, [BX + SI + 1]
JL L4
XCHG AL,[BX + SI + 1]
MOV [BX + SI],AL
L4: INC SI
LOOP L3
DEC DI
JNZ L2
MOV CX, DATA1
MOV SI, 1
MOV BX, OFFSET ARRAY
MOV AH,09
MOV DX,OFFSET msg3
INT 21H
L5: MOV DL, 0AH ; jump onto next line
MOV AH, 02H
INT 21H
MOV DX, [BX + SI]
INC SI
ADD DL, 30H
MOV AH, 02
INT 21H
LOOP L5
.EXIT

END

Write an assembly language binary search, program to search a sorted list.

4).Write an assembly language binary search, program to search a sorted list.

.model small
.386
.data
ARRAY DW 20 DUP (?)
DATA1 dw 0000H
DATA2 dw 0000H
success db 10,13,"Element is present in the array $"
fail db 10,13,"Element is not present in the arary $"
msg db 10,13,"Enter the size of the array :: $"
msg2 db 10,13,"Enter the array :: $"
msg3 db 10,13,"Enter the element to be searched :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV AH,01
INT 21H
SUB AL,30H
MOV AH,0
MOV CX,AX
MOV DATA1,AX
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV AH,0
MOV SI, 0
MOV BX, OFFSET ARRAY
L1: MOV DL, 0AH ; jump onto next line
MOV AH, 02H
INT 21H
MOV DX, SI ; input element of the array
MOV AH, 01H
INT 21H
SUB AL,30H
MOV SI, DX
MOV [BX + SI], AX
INC SI
LOOP L1
MOV AH,09
MOV DX,OFFSET msg3
INT 21H
MOV AH,01 ; Enter element to be searched
INT 21H
SUB AL,30H
MOV DATA2,AX
MOV CX,DATA1
MOV SI,0
MOV DI, DATA1
MOV BP, 0
MOV BX, OFFSET ARRAY
MOV AX, DATA1
L2: MOV SI, DI
ADD SI, BP
MOV AX, SI
MOV DL, 2
DIV DL
MOV AH,0
MOV DX,0
MOV SI,AX
MOV DX,DATA2
CMP [BX + SI],DL
JZ L3
CALL L4
LOOP L2
MOV AH, 09H
MOV DX,OFFSET fail ; if the element is not found
INT 21H
MOV AH, 4CH ; to forcefully terminate the program
INT 21H
L3: MOV AH, 09H
MOV DX,OFFSET success ; if the element is found
INT 21H
MOV AH, 4CH
INT 21H
L4 PROC NEAR
CMP [BX+SI], DL
JL L6
MOV DI, SI
RET
L6: MOV BP,SI
RET
L4 ENDP
.EXIT
END

Write an assembly language linear search, program to search a list.

3).Write an assembly language linear search, program to search a list.

.model small
.386
.data
ARRAY DW 20 DUP (?)
DATA1 dw 0000H
success db 10,13,"Element is present in the array $"
fail db 10,13,"Element is not present in the arary $"
msg db 10,13,"Enter the size of the array :: $"
msg2 db 10,13,"Enter the array :: $"
msg3 db 10,13,"Enter the element to be searched :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV AH,01
INT 21H
SUB AL,30H
MOV AH,0
MOV CX,AX
MOV DATA1,AX
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV AH,0
MOV SI, 0
MOV BX, OFFSET ARRAY
L1: MOV DL, 0AH ; jump onto next line
MOV AH, 02H
INT 21H
MOV DX, SI ; input element of the array
MOV AH, 01H
INT 21H
SUB AL,30H
MOV SI, DX
MOV [BX + SI], AX
INC SI
LOOP L1
MOV CX,DATA1
MOV AH,09
MOV DX,OFFSET msg3
INT 21H
MOV AH,01 ; Enter element to be searched
INT 21H
SUB AL,30H
MOV SI, 0
MOV BX, OFFSET ARRAY
L2: CMP [BX + SI], AL ; linear search loop
JZ L3 ; jump if element is found
INC SI
LOOP L2
MOV AH, 09H
MOV DX,OFFSET fail ; if the element is not found
INT 21H
MOV AH, 4CH ; to forcefully terminate the program
INT 21H
L3: MOV AH, 09H
MOV DX,OFFSET success ; if the element is found
INT 21H
MOV AH, 4CH
INT 21H
.EXIT

END

4 digits BCD Arithmetic (Addition and Subtraction of BCD numbers each 4 digits).

2).4 digits BCD Arithmetic (Addition and Subtraction of BCD numbers each 4 digits).

Addition:

.model small
.386
.data
DATA DW 0000H
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The Resultant sum is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV BX,0
MOV CX,4
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L2
SUB AL,30H
SHL BX,4
ADD BL,AL
LOOP AGAIN
MOV DATA,BX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV BX,0
MOV CX,4
AGAIN1:MOV AH,01 ;2nd NO. ENTERED
INT 21H
CMP AL,'A'
JGE L2
SUB AL,30H
SHL BX,4
ADD BL,AL
LOOP AGAIN1
MOV AX,DATA
MOV CX,0
ADD AL,BL
DAA
MOV BL,AL
ADC AH,BH
MOV AL,AH
DAA
MOV BH,AL
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV DX,0
MOV CX,4
AGAIN2: ROL BX,4
MOV DL,BL
AND DL,0FH
ADD DL,30H
MOV AH,02
INT 21H
LOOP AGAIN2
L2: .EXIT
END

Subtraction:

.model small
.386
.data
DATA dW 0000H
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The Resultant is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV BX,0
MOV CX,4
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L2
SUB AL,30H
SHL BX,4
ADD BL,AL
LOOP AGAIN
MOV DATA,BX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV BX,0
MOV CX,4
AGAIN1:MOV AH,01 ;2ND NO. ENTERED
INT 21H
CMP AL,'A'
JGE L2
SUB AL,30H
SHL BX,4
ADD BL,AL
LOOP AGAIN1
MOV AX,DATA
SUB AL,BL
DAS
MOV BL,AL
SBB AH,BH
MOV AL,AH
DAS
MOV BH,AL
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV CX,4
AGAIN2: ROL BX,4
MOV DL,BL
AND DL,0FH
ADD DL,30H
MOV AH,02
INT 21H
LOOP AGAIN2
L2: .EXIT
END

32-bit Binary Arithmetic (Addition, Subtraction, Multiplication and Division of 2 binary numbers each 32 bits).

1).32-bit Binary Arithmetic (Addition, Subtraction, Multiplication and Division of 2 binary
numbers each 32 bits).

Addition:

.model small
.386
.data
DATA1 dd 00000000H
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The Resultant sum is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV EBX,0
MOV CX,8
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L5
SUB AL,30H
JMP L6
L5: SUB AL,37H
L6: SHL EBX,4
ADD BL,AL
LOOP AGAIN
MOV DATA1,EBX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV EBX,0
MOV CX,8
AGAIN1:MOV AH,01 ;2nd NO. ENTERED
INT 21H
CMP AL,'A'
JGE L7
SUB AL,30H
JMP L8
L7: SUB AL,37H
L8: SHL EBX,4
ADD BL,AL
LOOP AGAIN1
ADD EBX,DATA1 ;ADDITION
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV CX,8
AGAIN2: ROL EBX,4
MOV DL,BL
AND DL,0FH
CMP DL,09
JG L1 ; to o/p given no.
ADD DL,30H
JMP PRINT
L1: ADD DL,37H
PRINT: MOV AH,02
INT 21H
LOOP AGAIN2
.EXIT
END

Subtraction:

.model small
.386
.data
DATA1 dd 00000000H
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The result is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV EBX,0
MOV CX,8
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L5
SUB AL,30H
JMP L6
L5: SUB AL,37H
L6: SHL EBX,4
ADD BL,AL
LOOP AGAIN
MOV DATA1,EBX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV EBX,0
MOV CX,8
AGAIN1:MOV AH,01 ;2nd NO. ENTERED
INT 21H
CMP AL,'A'
JGE L7
SUB AL,30H
JMP L8
L7: SUB AL,37H
L8: SHL EBX,4
ADD BL,AL
LOOP AGAIN1
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV EDX,DATA1
CMP EBX,EDX
JL L1
JMP L2
L1: MOV DATA1,EDX
MOV EDX,EBX
MOV EBX,DATA1
L2: SUB EBX,EDX ;SUBTRACTION FOR JB[EDX<EBX]
MOV CX,8
MOV EDX,0
AGAIN3: ROL EBX,4
MOV DL,BL
AND DL,0FH
CMP DL,09
JG L3 ; to o/p given no.
ADD DL,30H
JMP PRINT
L3: ADD DL,37H
PRINT: MOV AH,02
INT 21H
LOOP AGAIN3
.EXIT
END

Multiplication:

.model small
.386
.data
DATA1 dd 00000000H
DATA2 dd 00000000H
PROD1 dd ?
PROD2 dd ?
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The product(in hexadecimal) is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV EBX,0
MOV CX,8
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L5
SUB AL,30H
JMP L6
L5: SUB AL,37H
L6: SHL EBX,4
ADD BL,AL
LOOP AGAIN
MOV DATA1,EBX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV EBX,0
MOV CX,8
AGAIN1:MOV AH,01 ;2nd NO. ENTERED
INT 21H
CMP AL,'A'
JGE L7
SUB AL,30H
JMP L8
L7: SUB AL,37H
L8: SHL EBX,4
ADD BL,AL
LOOP AGAIN1
MOV DATA2,EBX
MOV EBX,0
MOV EDX,0
MOV EAX,0
MOV EAX,DATA1
MOV EBX,DATA2
MUL EBX
MOV PROD1,EDX
MOV PROD2,EAX
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV EBX,PROD1
MOV CX,8
AGAIN2: ROL EBX,4
MOV DL,BL
AND DL,0FH ; to o/p the result
CMP DL,9
JBE L1
ADD DL,37H
MOV AH,02
INT 21H
JMP L2
L1: ADD DL,30H
MOV AH,02
INT 21H
L2: LOOP AGAIN2
MOV EBX,PROD2
MOV CX,8
AGAIN3: ROL EBX,4
MOV DL,BL
AND DL,0FH ; to o/p the result
CMP DL,9
JBE L3
ADD DL,37H
MOV AH,02
INT 21H
JMP L4
L3: ADD DL,30H
MOV AH,02
INT 21H
L4: LOOP AGAIN3
.EXIT
END

Division:

.model small
.386
.data
DATA1 dd 00000000H
DATA2 dd 00000000H
REM dd ?
QUO dd ?
msg db 10,13,"Enter the first no.:: $"
msg1 db 10,13,"Enter the second no.:: $"
msg2 db 10,13,"The Remainder is :: $"
msg3 db 10,13,"The Quotient is :: $"
.code
.startup
MOV AH,09
MOV DX,OFFSET msg
INT 21H
MOV EBX,0
MOV CX,8
AGAIN: MOV AH,01 ;1ST NO. ENTERED
INT 21H
CMP AL,'A'
JGE L5
JMP L6
L5: SUB AL,37H
L6: SUB AL,30H
SHL EBX,4
ADD BL,AL
LOOP AGAIN
MOV DATA1,EBX
MOV AH,09
MOV DX,OFFSET msg1
INT 21H
MOV EBX,0
MOV CX,8
AGAIN1:MOV AH,01 ;2nd NO. ENTERED
INT 21H
CMP AL,'A'
JGE L7
SUB AL,30H
JMP L8
L7: SUB AL,37H
L8: SHL EBX,4
ADD BL,AL
LOOP AGAIN1
MOV DATA2,EBX
MOV EBX,0
MOV EDX,0
MOV EAX,0
MOV EAX,DATA1
MOV EBX,DATA2
DIV EBX
MOV REM,EDX ;REM=REMAINDER
MOV QUO,EAX ;QUO=QUOTIENT
MOV AH,09
MOV DX,OFFSET msg2
INT 21H
MOV EBX,REM
MOV CX,8
AGAIN2: ROL EBX,4
MOV DL,BL
AND DL,0FH ; to o/p the result in rem
CMP DL,9
JBE L1
ADD DL,37H
MOV AH,02
INT 21H
JMP L2
L1: ADD DL,30H
MOV AH,02
INT 21H
L2: LOOP AGAIN2
MOV AH,09
MOV DX,OFFSET msg3
INT 21H
MOV EBX,QUO
MOV CX,8
AGAIN3: ROL EBX,4
MOV DL,BL
AND DL,0FH ; to o/p the result in quo
CMP DL,9
JBE L3
ADD DL,37H
MOV AH,02
INT 21H
JMP L4
L3: ADD DL,30H
MOV AH,02
INT 21H
L4: LOOP AGAIN3
.EXIT
END

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...