MicroProcessors and MicroControllers
MicroProcessors and MicroControllers
Aim: Write a program to add two 16-bit numbers with/without carry using 8086.
Code:
MOV CX,0000H
MOV AX, [3000H]
MOV BX,[3002H]
ADD AX,BX
JNC ;A
INC CX
A : MOV [3004H], AX
MOV [3006H],CL
HLT
Data:
3000:12 3001:34
3002:43 3003:21
AX,3412H //0011 0100 0001 0010
BX,2143H //0010 0001 0100 0011
Result:
AX: 5555H 3004:55 3005:55
CX: 0000H 3006:00 3007:00
Code:
MOV CX,0000H
MOV AX, [3000H]
MOV BX,[3002H]
SUB AX,BX ; Jump if no borrow
JNC ; A
INC CX
A : MOV [3004H], AX
MOV [3006H],CL
HLT
Data:
3000:67 3001:54
3002:34 3003:21
AX,5467H //0101 0100 0110 0111
BX,2134H //0010 0001 0011 0100
Result:
AX: 3333H 3004:33 3005:33
CX: 0000H 3006:00 3007:00
Code:
MOV AL,03H
MOV BL,12H
MUL BL ; AX=AL*BL
MOV [3000H], AX
HLT
(ii)
MOV AX,000FH
MOV BX,000AH
DIV BX
MOV [0500H], AX
HLT
(i)
(ii)
Experiment 3
Aim: Write a Program to generate Fibonacci series.
Theory:
▪ The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144…(each number is the sum of the two
preceding ones, starting from 0 and 1).
▪ The Fibonacci sequence is generated by adding the (i)th element and the (i-1)th
element, and storing it into the (i+1)th position. This holds good given that the 1st
and 2nd positions are initialized with 0 and 1 respectively.
Code:
MOV CL,08H
MOV AX,00H
MOV BX,01H
//Fibonacci Part
L1:ADD AX,BX
MOV [SI],AX
MOV AX,BX
MOV BX,[SI]
INC SI
LOOP L1
HLT
//CL=8,0, 1, 1, 2, 3, 5, 8, 13
Theory:
▪ To find the factorial of a number n we have to repeatedly multiply the numbers from
1 to n. We can do the same by multiplying the number and decrease it until it reaches
1.
▪ In this program we are taking the number into counter register then decrease it and
multiply.
Code:
MOV CL,04H
MOV AL,01H
A: MUL CL
DEC CL
JNZ A
MOV [0500H], AL
HLT
Code:
CLD // CLD clear the directional flag, auto increments SI & DI register
MOV SI,0300 // MOV SI, 300 assigns 300 to SI
MOV DI,0400 // MOV DI, 400 assigns 400 to DI
MOV CX,0005 // MOV CX, 0005 assign 0000 to CX register
A: MOVSB // MOVSB
LOOPNZ A //*
HLT // HLT stops the execution of the program.
//*Special Note: The LOOP instruction assumes that the CX register contains the loop
count. When the loop instruction is executed, the CX register is decremented and the
control jumps to the target label, until the CX register value, i.e., the counter reaches the
value zero.