Google
Showing posts with label Assembly Language. Show all posts
Showing posts with label Assembly Language. Show all posts

Feb 13, 2010

A microprocessor Program to convert BCD pack and Unpack number for 8085.

Please find the Below program to Pack the two unpacked BCD numbers stored in memory locations 4200H and 4201H and store result in memory location 4300H. Assume the least significant digit is stored at 4200H.


Here is the Sample problem:
(4200H) = 04
(4201H) = 09
Result = (4300H) = 94


Source program for the above logic

LDA 4201H : Get the Most significant BCD digit
RLC
RLC
RLC
RLC : Adjust the position of the second digit (09 is changed to 90)
ANI FOH : Make least significant BCD digit zero
MOV C, A : store the partial result
LDA 4200H : Get the lower BCD digit
ADD C : Add lower BCD digit
STA 4300H : Store the result
HLT : Terminate program execution

Dec 14, 2008

program to find the sum of cubes of n numbers

program to find the sum of cubes of n numbers

initially we load the si and di registers and we initalize ax and cx registers to zero. we move ax to content of di and move contents of si to cl. the we continue to increment si and move si to al and multiply the current result with al. Then we move contents of si to that of bl and we multiply bl and add the result in ax to that of di and we repeat this till the loop ends

the code can be analyzed as follows

mov si,2000
mov di,4000
mov ax,0
mov cx,0
mov [di],ax
mov cl,[si]
inc si
mov al,[si]
mul al
mov bl,[si]
mul bl
add [di], ax
loop continue
int a5

Dec 8, 2008

program to perform fibonacci series

following program is perform fibonacci series

In order to perform the fibonacci series, that is 1,1,2,3,5,8,13 .....
We initalize SI to 2000 and CX to 0, then we initilaize AX and BX registers. Then we increment SI Register by 1 and we move the contents of AL into SI register. Then we decrement cs by one and move the contents of BL o that of si and decrement CS. Then we add al and the bl registers.

Move al with contents of si +01 and move si with BL, then we increment si by one and repeat until cx=0 and we halt the program

CODE:

MOV SI,2000
MOV CX,0000
MOV CL,[SI]
MOV AX,0000
MOV BX,00
INC SI
MOV [SI], AL
DEC CX
INC SI
MOV [SI],BL
DEC CX
AGAIN ADD AL,BL
MOV [SI+01],AL
MOV BL,[SI]
INC SI
LOOP AGAIN
INT A5

----
code ends

Dec 2, 2008

program to find the product of numbers in an array

This program is to find the product of numbers in an array:

We initalize the registers, then we move the size of the array to a counter and reduce its size bu one. SI is incremented to point to the 1st number of the array and move the 1st number into accumularot.

The 2nd number is moved into BL,, we multiply both the numbers abd this is continued till the numbers in the list, exhaust and finally the result is stored in AX.

Code:

MOV SI, 2000
MOV DI,4000
MOV AX,O
MOV BX,0
MOV CX,0
MOV CL,[SI]
SUB CL,[SI]
INC SI
MOV AL,[SI]
AGAIN: INC SI
MOV BL, [SI]
MUL BL
LOOP AGAIN
MOV [DI],AX
INT A5

Thus the program for product of numbers in an array can be executed using the above code.

Nov 28, 2008

Assembly program for a real time clock

Following is the Assembly language program for a real time clock

Code:

LCALL 061D
AGAIN MOV DPTR, #2845
REPEAT DEC82 ; Decrement DPL
MOVX A,@DPTR
MOV R3,A
MOV R5,#02
LCALL 059E
MOV A,20
LCALL 2006
MOVA,82
CJNE A,#42; REPEAT (ED)
MOVA,#OD ; OD = ASCII FOR ENTER
LCALL 2006
LJMP; AGAIN ( 6003 )

To change the RTC

2844-hrs
2843-minutes
2842-seconds

Oct 24, 2008

Program to interface DAC using 8255 and generate ramp waveform

Program to interface DAC using 8255 and generate ramp waveform

The following is the assembly language using DAC to interface with 8255 and generate a ramp on CRO. Here in the code, we use two jump instructions JMP and JZ in order to form the ramp wave. The jump instructions used in the program are iterated to repeat cycles of a ramp wave.

Code:

MOV DX,8807 : DX is loaded with control word register address of 8255
MOV AL,80
OUT DX,AL : Contents of AL are transferred to portA of 8255
MOV DX,8801 : DX is loaded with Port A address of 8255
Ramp MOV AL,00
Begin OUT DX,AL ; Contents of AL are transferred to portA of 8255
INC AL
CMP AL,FF
JZ Ramp
JMP Begin ; Repeat the same

Thus we programed in assembly language to interface DAC using 8255 to generate a ramp wave.

Related links
Ebooks for micro processors and micro controllers

Oct 21, 2008

Program to interface DAC using 8255 and generate square waveform


Program to interface DAC using 8255 and generate square waveform

The following is the assembly language using DAC to interface with 8255 and generate a square wave on CRO. Here in the code, we use two delay elements one for the rising part of the wave and the other delay element to reach zero i.e decrement. Certain value chosen is delayed or sustained for a time period to form the square wave. The two loops used in the program are iterated to repeat cycles of a square wave.



Code:

MOV DX,8807 : DX is loaded with control word register address of 8255
MOV AL,80
OUT DX,AL : Contents of AL are transferred to portA of 8255
MOV DX,8801 : DX is loaded with Port A address of 8255
Begin MOV AL,00
OUT DX,AL ; Contents of AL are transferred to portA of 8255
MOV CX,00FF
Delay1 Loop Delay1
MOV AL,FF
OUT DX,AL : Contents of AL are transferred to portA of 8255
MOV CX,00FF : CX is loaded with 00FFH
Delay2 Loop Delay2 : Repeat until CX=0
JMP Begin ; Repeat the same

The expected square wave can be observed as in the figure shown. Thus we programed in assembly language to interface DAC using 8255 to generate a square waveform.

Related links
Ebooks for micro processors and micro controllers

Assembly language program to find square root of 8-bit number

Following is the assembly language program to find square root of 8-bit number.
In this program we initially load the index registers with specified values. We load the value of the number into SI Register. Then using a few logical steps as mentioned in the code i.e JMP insctructions we find the square root of a 8-bit number.

Code:
MOV SI,2000
MOV DI,4000
MOV CX,0001
MOV BX,0000
MOV AL,[SI] ; Load AL with the value given as at SI
UP SUB AL,CL
JL down ; jump to down label
INC BL
ADD CL,02 ; add 2 to contents of CL register
JMP UP ; jump to up label
DOWN MOV[DI],BL
INT A5

Thus by implementing the above code we can find the square root of 8-bit number

Related posts
square root of hexa decimal number
Ebooks

You might be also interested in:

:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086
:: Assembly Language Source Codes

Oct 15, 2008

Program to interface stepper motor with 8086 and rotate with anti clock wise direction in full stepping

The following program is to interface stepper motor with 8086 and rotate with anti clock wise direction in full stepping. The purpose of this is to observe and control the stepping action of the motor using assembly language code. The code is also practically illustrated with two live demonstrations on how speed of the motor varies if one of the instruction codes is changed to a new value.

Code:

MOV DX,8807 : Load DX with control word register address of 8255
MOV AL,80 : load control word 80 into AL
OUT DX,AL: Contents of AL are loaded into control word register of 8255
MOV DX,8801: Load PortA address of 8255 into DX
MOV AL,33: Load value 33 into AL
Again OUT DX,AL: Contents of AL are loaded into control word register of 8255
MOV CX,0100: set counter to delay
Loop Again
ROL AL,1 : Rotate left by 1
JMP Again : Unconditional jump to label again

Following is the practical illsutration of the output for the above given code.



The instruction MOV CX,0100 can be changed to a new value in order to vary the speed.
So, for instance lets say MOV CX,7000. Following is the video demonstration of how the speed varies if the value is changed in the above instruction


Thus by changing the instruction the speed of the stepper motor can be varied according with interfacing it to an 8086 microprocessor for full stepping

Related posts:
Interfacing a stepper motor with an AVR Microprocessor

Interfacing a stepper motor with pic micro controller

Interfacing a stepper motor to 8086 using 8255

Sep 28, 2008

program to find factorial of given numbers

following is the assembly language program to find factorial of given numbers

MOV SI , 2000
MOV DI,2002
MOV CX,[SI]
MOV AX,CX ; Move contents of CX to contents of AX register
DEC CX ; Decrement CX
UP: MUL CX
DEC CX ; Decrement CX
JNZ; UP ; Jump if not zero
MOV [DI], AX ; Load the values of AX into location given by DI
INT A5; Halt the program

You might be also interested in:

:: Troubleshooting a simple 8086 microprocessor based microcomputer
:: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language
:: Data transfer instructions of 8086 microprocessor

Sep 26, 2008

Program to find arithmetic mean of n numbers

Program to find arithmetic mean of n numbers


CLC ; clear carry flag
MOV SI , 2000
MOV DI, 2050
MOV CX, 0000 ; Load CX register with the value given by 0000
MOV AX,0000
MOV CL,[SI]
MOV DL,CL
A1: INC SI ; Increment SI contents
ADD AL,[SI] ; ADD AL with the value given by that at SI and store in AL
LOOP AI ( 1011) ; Repeat until CX=0
DIV BL; Divide AX With the value given by BL
MOV [DI],AX ; Load the value in AX into as location at DI
INT A5 ; HALT

Thus with the above code the arithmetic mean of n numbers can found accordingly.

sample input:
0000:2000 array size
0000:20001 array elements
from 2001 location

Output
0000:2050 Result


You might be also interested in:

::Interfacing pic microcontroller with LCD
:: Serial Port interfacing with atmega
:: TCP/IP on PIC 18 series

Sep 24, 2008

assembly language program to reverse a given string

Following is the assembly language program to reverse a given string.

MOV AX @ DATA ; AX IS INITIALIZED WITH DATA
MOV DS AX ; AX IS MOVED INTO DS
MOV CX 0005H ; CX IS INITIALIZED TO 5
LEA SI A1 ; SI IS HAVING LEAD E.A OF A1
LEA DI A2; DI IS HAVING LEAD E.A OF A2
ADD SI 0004
AGAIN: MOV AL[SI]
MOV [DI]AL ; AL IS MOVED INTO DI
DEC SI
INC DI
LOOP AGAIN
INT 3 ; INTERRUPT
END

Using the above code if an Input for instance ' ad-cole': 0006 is given then the output will be shown as
DS: 0011: 16
10A0: 0010 : 65, 64 , 63 , 62 , 61 05 e d c b a

You might be also interested in:

:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086
:: Assembly Language Source Codes

Sep 23, 2008

stack program for push and pop

following is the assembly language program for push and pop operations in a stack.

code segment
main:
mov sp,1000h initialize SP to point to stack
mov ax,1234h
mov bx,5678h
mov cx,9abcdh
push ax
push cx
pop ax
pop ax
pop bx
pop cx
mov bx,0200h
mov w[bxx],1234h; address 0200 holds 1234
push [0200h]
push[bx]
mov bx,0210h
pop [bx]
pop[0212h]
imp main ; demo again
code ends

This program establishes the stack at 0100h and puts some random numbers in registers AX , BX , CX. AX is pushed on the stack that stores it at SS:OFFFh(MSB) and SS:0FFEh{LSB}. BX and CX are stored in similar manner with the attendant decrement of SP bt 2 for each push. The contents of the stack are then popped from the stack, in reverse order.

You might be also interested in:


:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086
:: Assembly Language Source Codes

Sep 13, 2008

Moving a bock of data from one location to another using assembly language

Following is the program code for Moving a bock of data from one location to another using assembly language . The size is initally stored in SI register and then SI is incremented to accept input number(s). Then the number is moved to AX and then to DI register. DI is incremented to store further numbers in the list. This is looped and the loop ends when counter becomes zero.

MOV SI,2000
MOV DI,4000
MOV CL,[SI]
INC SI : LABEL
MOV AX,[SI]
MOV [DI], AX
INC DI
LOOP LABEL
INT A5

You might be also interested in:

:: Interfacing Analog-to-Digital converter to 8086 using 8255
:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086
:: Assembly Language Source Codes

Aug 30, 2008

check wether given 16 bit number is palindrome or not

Palindrome program taking 16 bits.

taking C7H,EBH as given data i have done the program
which is equivalant to 1101011111101011

ORG 2000H
LXI H,2100H ;DATAS ARE STORED AT LOCATIONS 2100H,21001H
MOV A,M
MVI C,07H

LOOP: RRC
CALL SBR ;SBR IS SUBROUTINE
DCR C
JNZ LOOP

ANI 01H
ADD D
INX H
CMP M
LXI H,2400H ;1 IS STORED AT MEM-LOC 2400H IF PALIIN ELSE 0
JZ PALIN
MVI M,00H
JMP FIN

PALIN: MVI M,01H
FIN: HLT

SBR: MOV B,A
MOV A,D
JNC BYPAS ;IF CARRY IS NOT 1 IS NOT AADED
ADI 01H
BYPAS: RLC
MOV D,A
MOV A,B
RET

ORG 2100H
DB 00C7H,00EBH ;DATA BYTE

END

here EBH is reversed and compared with C7H, if they are equal then plain else not palin


You might be also interested in:

:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI
:: Interfacing Stepper Motor to 8086 using 8255

Jul 22, 2008

8086 program to find GCD of two 2 numbers

Euclid (a Greek mathematicians and philosopher of about 300 BC) describes this algorithm in Propositions 1 and 2 of Book 7 of The Elements, although it was probably known to the Babylonian and Egyptian mathematicians of 3000-4000 BC also.
If we try it with an two numbers, the final non-zero remainder is the greatest number that is an exact divisor of both our original numbers (the greatest common divisor)


Here is the program


mov ax,4000h
mov ds,ax
mov si,0000h
mov al,num1 ;num1 is first no.
mov cl,num2 ;num2 is second no.
mov ah,00h
cmp al,cl
ja next
xchg al,cl
next: mov bl,cl
div cl
cmp ah,00h
je down
mov al,cl
mov cl,ah
mov ah,00h
jmp next
down mov result,bl ;result is the mem.loc.
;where gcd is to be stored
hlt

You might be also interested in:

:: options available for int 21h instruction
:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing

Jul 6, 2008

decimal addition program for 8086

This program will add two decimal numbers

LXI H,2200H
MOV A,M
INX H
ADD M
DAA
STA 2300H
HLT

DAA will convert HEX to valid BCD number
now the program can be easily understood

You might be also interested in:


:: 8051 or PIC microcontroller which is better
:: Effective addresses
:: Floating Point Initializations

Jun 30, 2008

A subroutine program in assembly language

A subroutine based program in assembly language.

this is the MAIN PROGRAM

LXI SP 2400H
LXI H,2000H
LXI B,1020H
CALL SUB
HLT

this is the subroutine
SUB: PUSH B
PUSH H
LXI B,4080H
LXI H,4090H
DAD B
SHLD 2200H
POPH
POPB
RET

this subroutine is some thing like functions in c program language. here the main function is calling the subroutine SUB in the last but one line then the flow of the execution of the program is transfered to the subroutine once the program flow is reached to the end of the subroutine i.e RET statement then the execution will be going to the main program.


You might be also interested in:

:: free and open source 8086 Microprocessor Emulator
:: Invoke function

Jun 28, 2008

whether given number is palindrome or not

This is assembly language program for finding a given number is palindrome or not

Example:
3000 – AD
3001 – B5

AD = 10101101
B5 = 10110101 (D7=1; D6=0; D5=1; D4=1; D3=0; D2=1; D1=0; D0=1)

AD and B5 are palindrome

Algorithm
1. Take the 2nd value B5
2. The binary equivalent of it (10110101), is cut into bits n each bit is put in address ranging from 8001 to 8008 in the reverse order. That is, D0 is put in 8001; D1 in 8002 and so on—until D7 in 8008
3. This is done by rotating 10110101 right thro carry
4. Thus the carry values are stored into the addresses (8001 – 8008)
5. Hence we get, 8001 – 00000001
8002 – 00000000
8003 – 00000001
8004 – 00000000
8005 – 00000001
8006 – 00000001
8007 – 00000000
8008 – 00000001
6. Each of these values hafta b shifted so as to get 10000000 of 8001
00000000 of 8002
00100000 of 8003
00000000 of 8004
00001000 of 8005
00000100 of 8006
00000000 of 8007
00000001 of 8008
7. Add the values present in 8001 to 8008 n store it in the register C. Hence in register C, we have the value AD after rotating B5)
8. Get the 1st value from 3000 n store it in accumulator (register A)
9. Subtract A and C registers
10. If the numbers are palindrome, 01h gets stored in memory 4000
11. If the numbers r not palindrome, 02h is stored in memory 4001
12. end

the program

Label Mnemonics

MVI H, 08h
MVI L, 01h
MVI C, 08h
LDA 3001
rotate: RAR
JC one
JNC zero
one: MVI M, 01h
JMP next
Zero: MVI M, 00h
Next: INC L
DCR C
JNZ rotate
MVI L, 00h
Inc: INC L
MOV D, L
MOV A, L
SUI 09h
JZ fini
MOV A, M
Hey: RRC
DCR D
JZ inc
JNZ hey
Fini: MVI L, 00h
MVI C, 00h
Other: INC L
MOV A, M
MOV B, A
INC L
MOV A, M
ADD B
ADD C
MOV C, A
MOV A, L
SUI 08h
JNZ other
MVI H, 30h
MVI L, 00h
MOV A,M
SUB C
JZ palin
JNZ nopalin
Palin: MVI A, 01h
STA 4000
JMP over
Nopalin: MVI A, 02h
STA 4001
Over: HLT

You might be also interested in:

:: Assembly Language Programs to compute an expression
:: Interfacing Analog-to-Digital converter to 8086 using 8255
:: Interfacing Digital-To-Analog converter to 8086 using 8255
:: Temperature Control system using 8086

Jun 26, 2008

seperate the digits of hexa decimal number assembly language program

seperate the digits of a hexa decimal numbers and store in different locations

first get the packed BCD number and mask the lower nibble then move to the required position in the number and adjust the higher BCD digit as a lower digit then store the partial result now get the orignal BCD number and mask the higher nibble store the result and stop the program

LDA 2200H
ANI F0H
RRC
RRC
RRC
RRC
STA 2300H
LDA 2200H
ANI 0FH
STA 2301H
HLT

You might be also interested in:

:: Assembly Language Source Codes
:: why there are two ground pins in 8086
:: Program to display ASCII characters on the display unit