You are on page 1of 19

EXPERIMENT 1

Aim-To write and simulate programs for arithmetic operations Addition,


Subtraction, Multiplication and Division
21BRS1686 SHRESTHA SINGH
RESOURCES
The 8086 Microprocessor kit, Power Supply.

Procedure.
1. Turn on the microprocessor kit with the keyboard connected.
2. Type ‘A’ and press Enter.
3. Type ‘1000’ as the starting address, press Enter.
4. Type out each program code line followed by an Enter and note down the address and
opcode for each.
5. After the last line, press Reset button and type ‘GO 1000’, then press Enter.
6. Press Reset again and then type ‘SB [address]’, then note values of the result in the result
address, which should be the result of the operation.

ADDITION
mov ax, 5 ; move the value 5 into register ax
mov bx, 3 ; move the value 3 into register bx
add ax, bx ; add the contents of bx to ax
; the result is now in ax
SUBSTRACTION
MOV AX, [NUM1] ; Move the first number to AX
MOV BX, [NUM2] ; Move the second number to BX
SUB AX, BX ; Subtract BX from AX
MOV [RESULT], AX ; Move the result to memory location RESULT
MULTIPLICATION
MOV AX, [NUM1] ; Move the first number to AX
MOV BX, [NUM2] ; Move the second number to BX
MUL BX ; Multiply AX by BX
MOV [RESULT], AX ; Move the result to memory location RESULT
DIVISION
MOV AX, [NUM1] ; Move the first number to AX
MOV BX, [NUM2] ; Move the second number to BX
DIV BX
MOV [2000], AX
HLT
Program Table(s)- VERIFIED
PROGRAM LOGIC
We use ADD instruction for addition and SUB instruction for subtraction. ADD instruction adds an
immediate data or contents of a memory location specified in the instruction or a register (source)

to the contents of another register (destination) or memory location. The result is in the destination
operand. However, both the source and destination operands cannot be memory operands. That
means memory to memory addition is not possible. Also the contents of the segment registers
cannot be added using this instruction. All the condition code flags are affected depending upon the
result.

Hence one of the operands is initially moved to AL OR AX. Then using the add instruction, 8
bit or 16-bit addition is performed.
The next arithmetic primitive is SUB. As discussed in ADD it permits the same modes of
addressing. Hence moving the minuend to a register pair is necessary. Then the result is moved to a
location in memory. The 8086 Processor provides both signed and unsigned multiply in their instruction set
to
overcome the loss of efficiency in performing the repeated addition.

For multiplication, we use MUL instruction and for division we use DIV instruction.MUL
instruction multiplies unsigned byte or word by the content of AL. The unsigned byte or word may
be in any one of the general-purpose register or memory locations. The most significant word of
result is stored in DX, while the least significant word of the result is stored in AX. All the flags are
modified depending upon the result. Immediate operand is not allowed in this instruction.

DIV instruction divides an unsigned word or double word by a 16-bit or 8-bit operand. The
dividend must be in AX for 16-bit operation and divisor may be specified using any one of the
addressing modes except immediate. The result will be in AL (quotient) while AH will contain the
remainder. If the result is too big to fit in AL, type 0(divide by zero) interrupt is generated. In case of
a double word dividend (32-bit), the higher word should be in DX and lower word should be in AX
21BRS1686 SHRESTHA SINGH
Experiment – 2 / BECE204P
Aim
To write and simulate programs for addition with carry, average of three numbers, sum of
array of numbers and sum of array elements of two arrays.
ADDITION WITH CARRY
MOV AX,[2000]
MOV BX,[2002]
ADD AX,BX
MOV CL,00
JNC 1011
INC CL
MOV [2004],AX
MOV [2006],CL
HLT
AVERAGE OF 3 NUMBERS
MOV BX,3H
MOV AX,2H
ADD AX,2H
ADD AX,2H
DIV BX
MOV [2000],AX
HLT
SUM OF ARRAY OF NUMBERS
MOV CX, 0005H
MOV AX,0000H
MOV BX, 0000H
MOV SI, 2000H
REPEAT
MOV BL,[SI] - 1010
ADD AX,BX
INC SI
DEC CX
JNZ REPEAT - 1010
MOV DI,3000H
MOV [DI],AX
HLT
SUM OF CORRESPONDING ELEMENTS OF TWO ARRAYS
MOV CX,0005H
MOV SI,2000H
MOV DI,3000H
MOV AL,[SI] - ADDRESS
ADD AL,[DI]
MOV SI,AL
INC SI
INC DI
LOOP ADDRESS
HLT
Procedure
1. Turn on the microprocessor kit with the keyboard connected.
2. Type ‘A’ and press Enter.
3. Type ‘1000’ as the starting address, press Enter.
4. Type out each program code line followed by an Enter and note down
the address and opcode for each.
5. Type ‘GO 1000’, then press Enter.
6. Type ‘SB 2000’ and check the values in those addresses, they should
be the desirable outputs.
PROGRAM LOGIC In this program, we need to calculate the sum of 6 numbers. The initial
sum is assumed as zero. Initially, the resulting sum of the first two numbers will be stored.
To this sum, the third number will be added. This procedure will be repeated till all the
numbers in the series are added. The sum procedure here is to be repeated for 6 times as
there are 6 numbers. So here the value 6 will be stored in counter register CX.
To implement the counter checking logic, we can do it in any one of the following ways:
a. A conditional JUMP instruction will be used to implement the counter checking logic.
b. An unconditional Loop instruction can be used to implement the counter checking logic
with the help of CX register.
Program Table(s)- VERIFIED-
21BRS1686 SHRESTHA SINGH
MICROPROCESSORS AND MICROCONTROLLERS
Experiment – 3 / BECE204P
Aim- To write and simulate programs for sorting of numbers in ascending and
descending order
Procedure
1. Turn on the microprocessor kit with the keyboard connected.
2. Type ‘A’ and press Enter.
3. Type ‘1000’ as the starting address, press Enter.
4. Type out each program code line followed by an Enter and note down
the address and opcode for each.
5. Press Reset again and then type ‘SB 2000’, then put value of the
number in the address followed by Enter which are to be sorted and press
Reset.
6. Type ‘GO 1000’, then press Enter.
7. Press Reset and type ‘SB 2000’ and check the values in those
addresses, they should be now sorted in respective manner.

PROGRAM LOGIC To arrange the given numbers in ascending and descending order, the bubble sorting
method is used. Initially the first number of the series is compared with the second one. If the first number
is greater than second, exchange their positions in the series otherwise leave the position unchanged. Then
compare the second number in the recent form of the series with third and repeat the exchange part that
you are carried out for the first and second number, and for all the remaining number of the series. Repeat
this procedure for complete series (n-1) times. After n-1 iterations you will get the largest number at the
end of the series. Again start from the first number of the series. Repeat the same procedure right from
the first element to the last element. After n-2 iteration you will get the second highest number at the last
but one place in the series. Repeat this till the complete series is arranged in ascending order.

RESOURCES The 8086 Microprocessor kit, Power Supply

Program Table(s)- VERIFIED- mov cx, 5 ; set the number of elements in the array

mov bx, offset array ; set the starting address of the array
mov dx, cx ; set the counter for outer loop
sort_loop: ; start of outer loop
mov cx, dx ; set the counter for inner loop

inner_loop: ; start of inner loop


mov ax, [bx] ; load current element into ax
cmp ax, [bx+2] ; compare current element with next element
jle skip ; if current element <= next element, skip swap
mov dx, [bx+2] ; load next element into dx

mov [bx+2], ax ; store current element in next element's location


mov [bx], dx ; store next element in current element's location
skip:
add bx, 2 ; move to next element
loop inner_loop ; repeat inner loop

sub dx, 1 ; decrement outer loop counter


loop sort_loop ; repeat outer loop
SNAPSHOTS OF OUTPUTS EXPERIMENT NUMBER 3
ASCENDING ORDER
DESCENDING ORDER
MICROPROCESSOR AND MICROCONTROLLER
SHRESTHA SINGH
21BRS1686
PROFESSOR – SHOBA S
EXPERIMENT 4 AND 5
EXPERIMENT 4
AIM-Assembly code for code converters in 8086 processor.

PROCEDURE-
1.Take a 16 bit microprocessor attach to the usb cable.
2.Type A press enter.
3.Take starting address as 1000.
4.Give the instructions and end then code with halt.
5.Type GO and press ENTER.
6.Reset it and type SB 2000 stored data and press ENTER.
Result: Input : 0000 : 2000 – 25 25 Output: 0000 : 3000 – 19

OUTPUT-
EXPERIMENT 5 (A)
BCD TO ASCII
SHRESTHA SINGH
21BRS1686

AIM- Write assembly code for 16 bit 8086 microprocessor for the BCD to ASCII.

PROCEDURE –
1) Take a 16-Bit Microprocessor kit and attach USB with Keyboard.
2) Type ‘A’ and press ‘Enter’
3) Type starting address as 1000
4) Start writing the instructions and press ‘Enter’ two times for each
instruction
5) After ending the code, press ‘HLT’ and press ‘Reset’
6) Then type ‘GO 1000’ (1000 being the starting address)
7) Reset it and type SB 2000 and press ‘Enter’

2. BCD to ASCII

Result: Input : SB 2000 – 98 Output: SB 3000 – 39 SB 3001 – 38

OUTPUT-
EXPERIMENT 5(B)
SHRESTHA SINGH
21BRS1686
MICROPROCESSOR AND MICROCONTROLLER

AIM- To write the assembly code for 16 bit microprocessor 8086 for factorial of a number.
PROCEDURE-
1) Take a 16-Bit Microprocessor kit and attach USB with Keyboard.
2) Type ‘A’ and press ‘Enter’
3) Type starting address as 1000
4) Start writing the instructions and press ‘Enter’ two times for each
instruction
5) After ending the code, press ‘HLT’ and press ‘Reset’
6) Then type ‘GO 1000’ (1000 being the starting address)
7) Reset it and type SB 2000 and press ‘Enter

Result: Input : SB 2000 – 04H Output: SB 3000 – 18H

OUTPUT-

You might also like