Thursday, March 29, 2012

Find the factorial of a given number using 8086 program in assembly language


ASSUME  CS:CODE, DS:DATA, SS:STACK1
DATA SEGMENT
NUM DW 05H
FACT DW 0H
DATA ENDS
STACK1 SEGMENT
STK DW 100H DUP(0H)
TOP_STACK LABEL WORD
STACK1 ENDS
CODE SEGMENT
START:  MOV AX, DATA
        MOV DS, AX
        MOV AX, STACK1
        MOV SS, AX
        LEA SP, TOP_STACK
        MOV AX, NUM
        CALL FACTO1
        MOV AH, 4CH
        INT 21H
        FACTO1 PROC NEAR
        CMP AX, 01H
        JE GO
        PUSH AX
        DEC AX
        CALL FACTO1
        POP AX
        MUL FACT
        MOV FACT, AX
        RET
GO:     MOV FACT,01H
        RET
        FACTO1 ENDP
        CODE ENDS
        END START
     

Finding the number of even and odd numbers in a given series in assembly language using 8086



ASSUME  CS:CODE, DS:DATA
DATA    SEGMENT
        ORG 5000H
SERIES  DB 35H,66H,11H,12H,22H,56H,8H,2H,1H,9H
COUNT   DB 0AH
ODDCOUNT DB 00H
EVENCOUNT DB 00H
DATA    ENDS
CODE    SEGMENT
START:  MOV AX, DATA
        MOV DS, AX
        LEA SI, SERIES
        MOV CL, COUNT
NEXT:   MOV AX, [SI]
        ROR AX, 01
        JNC EVENV
        INC ODDCOUNT
        JMP OTHER
EVENV:   INC EVENCOUNT
OTHER:  INC SI
        DEC CL
        JNZ NEXT
        MOV AH, 4CH
        INT 21H
CODE    ENDS
        END START


Data transfer in reverse direction in assembly language in 8086


assume cs:code,ds:data
data segment
org 2000h
array1 db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
org 4000h
array2 db 10d dup(0h)
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2000h
mov di,4009h
mov cx,10d
go:mov al,[si]
mov [di],al
inc si
dec di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start

Addition of two numbers in assembly language using 8086


ASSUME CS:CODE, DS:DATA
DATA    SEGMENT
        ORG 3000H
        NUM1 DB 22H
        NUM2 DB 32H
        SUM DB 00H
DATA    ENDS
CODE    SEGMENT
        ASSUME CS:CODE, DS:DATA
START:  MOV AX, DATA
        MOV DS, AX
        MOV AL, NUM1
        MOV BL, NUM2
        ADD AL, BL
        MOV SUM, AL
        MOV AH, 4CH
        INT 21H
CODE ENDS
        END START

Monday, March 26, 2012

Data transfer in forward direction in assembly language using 8086


assume cs:code,ds:data
data segment
org 2000h
array1 db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
org 4000h
array2 db 50d dup(0h)
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2000h
mov di,4000h
mov cx,10d
go:mov al,[si]
mov [di],al
inc si
inc di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start

Data Over laping in assembly language using 8086


assume cs:code,ds:data
data segment
org 2000h
array db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0ah
data ends
code segment
start:mov ax,data
mov ds,ax
mov si,2009h
mov di,200eh
mov cx,10d
go:mov al,[si]
mov [di],al
dec si
dec di
dec cx
jnz go
mov ah,4ch
int 21h
code ends
end start


LCD INTERFACING using 8051/89c51 using TOPView Simulator




2 lines 16 characters, 8 bits, port line selection EN - P3.2,RS - P3.1,RW - P3.3


$MOD51
 EN EQU P3.2
RS EQU P3.1
RW EQU P3.3
ORG 0000H
MOV A,#38H
LCALL LCD_COMD
MOV A,#0EH
LCALL LCD_COMD
MOV A,#06H
LCALL LCD_COMD
MOV A,#01H
LCALL LCD_COMD
MOV A,#'E'
LCALL LCD_TEXT
MOV A,#'C'
LCALL LCD_TEXT
MOV A,#'E'
LCALL LCD_TEXT
LOOP:SJMP LOOP
LCD_COMD:CLR C
LCALL WRITE
RET
LCD_TEXT:SETB C
LCALL WRITE
RET
WRITE:SETB EN
CLR RW
MOV RS,C
MOV P1,A
CLR EN
LCALL DELAY
RET
DELAY: MOV R0,#56
LOOP2: MOV R1,#255
LOOP1: DJNZ R1,LOOP1
             DJNZ R0,LOOP2
RET
END

INTERFACING OF 2 DIGIT SEVENSEGMENT DISPLAY THROUGH 7447 In 89c51/8051 with topview simulator


NOTE: When initializing the external modules set these settings
NON Multiplexed, green or red, common cathode, BCD.
Port line selections:
Number digits -2,
Control line and port line:
CONNECT PORT1.0 TO 1.4 BITS TO DIGIT2 AND PORT 1.4 TO 1.7 TO DIGIT1

$MOD51
ORG 0000H
        SJMP MAIN
ORG 0030H
MAIN: MOV A,#00H
AGAIN:MOV P 1,A
        LCALL DELAY
       ADD A,#01
        DA A
        SJMP AGAIN
;DELAY ROUTINE
        ORG 0040H
DELAY:         MOV R2,#0FFH
UP1:    MOV R1,#0FFH
UP2:   NOP
       NOP
       NOP
        DJNZ R1,UP2
        DJNZ R2,UP1
        RET
        END

INTERFACE OF LEDS TO GET THE TOGGLE OPERATION in 8051/89c51 in topview simulator


$mod51
mov a,#0aah
repeat: mov p1,a
         cpl a
        lcall delay
        sjmp repeat
delay:mov r2,#0ffh
back:mov r1,#0ffh
up1:nop
nop
djnz r1,up1
djnz r2,back
ret
end

Sunday, March 25, 2012

Finding the compliment of numbers using 89c51 microcontroller and topview simulator


$mod51
Org 0000h
mov dptr,#0100h
movx a,@dptr
cpl a
inc dptr
movx @dptr,a
stop:sjmp stop
end

Division of two numbers using 89c51 microcontroller


$mod51
org 0000h
mov dptr,0100h
movx a,@dptr
inc dptr
movx b, @dptr
div a,b
inc dptr
movx @dptr,a
mov a,b
inc dptr
movx @dptr,a
stop:sjmp stop
end

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...