You are on page 1of 12

EC-407

VHDL PROGRAMMING

FILE

Abhinav Malhotra
03/EC/07
INDEX

1. To find out the largest number from a given unordered array of 8- bit numbers,
stored in locations starting from a known address.
2. To find out the number of even and odd numbers from a given series of 16-bit
hexadecimal numbers.
3. To find out the number of positive and negative numbers from a given series of
signed hexadecimal numbers.
4. To move a string of data words from offset 2000H to 3000H, when length is 0FH.
5. To arrange a given series of hexadecimal bytes in ascending order.
6. To perform one byte BCD addition.
7. To perform addition, subtraction, multiplication and division of numbers.
8. To decide whether the parity of a given number is even or odd. If even, set DL to
00, else 01. The given number may be a multi byte number.
9. To convert a BCD number to an equivalent binary number.
10. To find out the square root of a given number, assuming it to be a perfect square.
Experiment No:1

AIM: To find out the largest number from a given unordered array of 8- bit numbers,
stored in locations starting from a known address.

Logic: The 1st number of the array is taken in a register, say AL. The 2nd number of
array is then compared with the 1st one. If the 1st one is greater than 2nd one, it is left
unchanged. However, if the 2nd one is greater than 1st, 2nd number replaces the 1st one
in the AL register. The procedure is repeated for every number in array and thus requires
15 iterations.

MOV CX, 0FH; Initialize counter for no. of iterations


MOV AX, 2000H; Initialize data segment
MOV DS, AX;
MOV SI, 0500H; Initialize source pointer
MOV AL, [SI]; Take 1st number in AL
BACK: INC SI;
CMP AL,[SI];
INC SI;
CMP AL,[SI];
JNC NEXT;
MOV AL,[SI];
NEXT: LOOP BACK; Repeat the procedure 15 times
HLT
Experiment No: 2

AIM: To find out the number of even and odd numbers from a given series of 16-bit
hexadecimal numbers.

MOV AX,1000H
MOV DS,AX
MOV BX,0000H
MOV DX,0000H

MOV CX,13H
MOV SI,100H
L2: MOV AX,[SI]
RCR AX,01H
JNC L1
JMP L5
L1: INC BL
L5: INC SI
INC SI
LOOP L2
MOV CX,13H
MOV SI,100H
L3: MOV AX,[SI]
RCL AX,01H
JNC L4
JMP L6
L4: INC DL
L6: INC SI
INC SI
LOOP L3
MOV AL,14H
SUB AL,DL
MOV DH,AL
MOV AL,14H
SUB AL,BL
MOV BH,AL
HLT
Experiment No: 3

AIM: To find out the number of positive and negative numbers from a given series of
signed hexadecimal numbers.

Logic: Take a number and rotate it left through carry. The status of carry flag will give
the sign of the number. If CF=1, the number is negative, otherwise positive.

START: XOR BX,BX


XOR DX,DX
MOV AX,DATA
MOV DS,AX
MOV CL,COUNT
MOV SI, OFFSET

AGAIN: MOV AX,[SI]


SHL AX,01
JC NEG
INC BX
JMP NEXT
NEG: INC DX
NEXT: ADD SI,02
DEC CL
JNZ AGAIN
MOV AH,4CH
INT 21H
END START
Experiment No: 4

AIM: To move a string of data words from offset 2000H to 3000H, when length is 0FH.

MOV SI,2000H
MOV DI,3000H
MOV CX,0FH
AGAIN: MOV AX,[SI]
MOV [DI],AX

ADD SI,02H
ADD DI,02H
DEC CX
JNZ AGAIN
HLT
Experiment No: 5

AIM: .To arrange a given series of hexadecimal bytes in ascending order.

START: MOV AX, DATA


MOV DS, AX
MOV DX, COUNT-1
AGAIN0: MOV CX,DX
MOV SI,OFFSET
AGAIN1: MOV AX,[SI]
CMP AX,[SI+2]
JL PR1
XCHG [SI+2], AX
XCHG [SI], AX
PR1: ADD SI, 02
LOOP AGAIN1
DEC DX
JNZ AGAIN0
MOV AH, 4CH
INT 21H
END START
Experiment No: 6

AIM: .To perform one byte BCD addition.

START: MOV AX,DATA


MOV DS,AX
MOV BL,OPR1
XOR AL,AL
MOV AL,OPR2
ADD AL,BL
DAA
MOV RESULT,AL
JNC MSB0
INC [RESULT+1]
MSB0: MOV AH,4CH
INT 21H
END START
Experiment No: 8

AIM: .To decide whether the parity of a given number is even or odd. If even, set DL to
00, else 01. The given number may be a multi byte number.

START: MOV AX,DATA


MOV DS,AX
MOV DH, BYTE_COUNT
XOR AL,AL
MOV CL,00
MOV SI,OFFSET
NEXT_BYTE:ADD AL,[SI]
JP EVENP
INC CL
EVENP: INC SI
MOV AL,00
DEC DH
JNZ NEXT_BYTE
MOV DL,00
RCR CL,1
JNC CLEAR
INC DL
CLEAR: MOV AH,4CH
INT 21H
END START
Experiment No: 9

AIM: To convert a BCD number to an equivalent binary number.

MOV CX,08H
MOV AX,2000H
MOV DS,AX
MOV SI,100H
MOV AX,35H
L1: SHR AX,01H
RCR BX,01H
LOOP L1
HLT
Experiment No: 10

AIM: To find out the square root of a given number, assuming it to be a perfect square.

START: MOV AX,DATA ; initialize data segment


MOV DX,AX
MOV CL, NUM ; number is transferred to CL
MOV BL,1 ; BL is initialized to 1
MOV AL,0 ; AL is initialized to 0
UP: CMP CL,0 ; Check for zero number
JZ ZRESULT ; if zero, go to zresult label
SUB CL,BL ; if not, do CL-BL
INC AL ; increment the content of AL
ADD BL,02 ;add 2 to register BL
JMP UP ; go back to label UP
ZRESULT: MOV RESULT,AL ; result saved in data segment
MOV AH,4CH
INT 21H
END START

You might also like