• This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Official Notes - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Official Notes - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Official Notes - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Official Notes - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Official Notes - Premiumbloggertemplates.com.

Showing posts with label Assembly Programming. Show all posts
Showing posts with label Assembly Programming. Show all posts

Assembly Program for Multiplying 5 digit numbers


;----------------------------------------------------------------------------   

    PAGE    58,132

;----------------------------------------------------------------------------

;    DISPLAY
;
;    Purpose:
;        to multiply 5 digit number

;----------------------------------------------------------------------------

    TITLE    DISPLAY-multiplication
    .MODEL SMALL
    .286

    .STACK

;----------------------------------------------------------------DATA segment
   
    .DATA
MSG1    DB    "MULTIPLICATION OF 5 DIGIT INTEGERS",0DH,0AH
L_MSG1    EQU    $-MSG1
MSG2    DB    "ENTER FIRST NUMBER:"
L_MSG2    EQU    $-MSG2
NUM1    DB    7 DUP(?)
MSG3    DB    "ENTER SECOND NUMBER:"
L_MSG3    EQU    $-MSG3
NUM2    DB    7 DUP(?)
MSG4    DB    "PRODUCT="
L_MSG4    EQU    $-MSG4
PRO    DB    11 DUP(?)
TOOL    DB    ?

;----------------------------------------------------------------CODE segment

    .CODE
    PAGE

;----------------------------------------------------------------------------

;Procedure: MAIN

MAIN    PROC    FAR
.STARTUP

;displays MSG1------welcome note
    MOV    BX, 0001H
    LEA    DX, MSG1
    MOV    CX, L_MSG1
    MOV    AH, 40H
    INT    21H   
;displays MSG2------asking of operand1       
    MOV    BX, 0001H
    LEA    DX, MSG2
    MOV    CX, L_MSG2
    MOV    AH, 40H
    INT    21H   
;get entry of first number
    MOV     CX,7
    LEA    DX,NUM1
    MOV     AH, 3FH
    MOV    BX, 0000H
    INT    21H
;displays MSG3-------asking of operand2
    MOV    BX, 0001H
    LEA    DX, MSG3
    MOV    CX, L_MSG3
    MOV    AH, 40H
    INT    21H
;get entry of second number
    MOV     CX,7
    LEA    DX,NUM1
    MOV     AH, 3FH
    MOV    BX, 0000H
    INT    21H

;conversion of entries from ASCII to BCD
    LEA    SI, NUM1
    CALL    ASCII_TO_BCD
    LEA    SI, NUM2
    CALL    ASCII_TO_BCD
;to have a space of one line
    MOV    AH,2H
    MOV    DX,0DH
    INT    21H
    MOV    DX,0AH
    INT    21H
;displays MSG4-------display of product
    MOV    BX, 0001H
    LEA    DX, MSG4
    MOV    CX, L_MSG4
    MOV    AH, 40H
    INT    21H
;defining register for multiplication
    LEA    SI,NUM1
    LEA    BX,NUM2
    LEA    DI,PRO
    CALL    MULTIPLICATION

;conversion of product form BCD to ASCII
    CALL    BCD_TO_ASCII

;display product
    LEA    DX,PRO
    MOV    CX,10
    MOV    AH, 40H
    MOV    BX,0001H
    INT    21H

.EXIT
MAIN ENDP

;*******************************PROCEDURES***********************************

;----------------------------------------------------------------------------

;ASCII_TO_BCD
;Purpose:
;    -to convert the entries from ASCII to BCD
;Input:
;    -[SI]
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure:ASCII_TO_BCD

ASCII_TO_BCD PROC
   
    PUSHA

TO_BCD:
    MOV    AL,[SI]
    CMP    AL,0DH
    JE    END_BCD
    SUB    AL, 30H
    MOV    [SI], AL
    INC    SI
    JMP    TO_BCD

END_BCD:
    MOV    TOOL,-1
SHIFT:   
    ADD    TOOL,1
    MOV    DL,[SI+6]
    CMP    DL,TOOL
    JE    END_SHIFT
    CMP    TOOL,9
    JL    SHIFT
    MOV    DL,[SI+5]
    MOV    [SI+6],DL
    MOV    DL,[SI+4]
    MOV    [SI+5],DL
    MOV    DL,[SI+3]
    MOV    [SI+4],DL
    MOV    DL,[SI+2]
    MOV    [SI+3],DL
    MOV    DL,[SI+1]
    MOV    [SI+2],DL
    MOV    DL,[SI]
    MOV    [SI+1],DL
    MOV    DL,0
    MOV    [SI],DL
    MOV    COUNT,-1
    JMP    SHIFT

END_SHIFT:   

    POPA
    RET
ASCII_TO_BCD    ENDP

;----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;BCD_TO_ASCII
;Purpose:
;    -to convert the procudt from BCD tO ASCII
;Input:
;    -[SI]
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure: BCD_TO_ASCII

BCD_TO_ASCII PROC
    LEA    DI,PRO
   
    PUSHA

TO_ASCII:
    MOV    AL,[DI]
    CMP    AL,0DH
    JE    END_ASCII
    ADD    AL, 30H
    MOV    DI, [AL]
    INC    DI
    JMP    TO_ASCII

END_ASCII:
   
    POPA
    RET
BCD_TO_ASCII ENDP

;-----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;MULTIPLICATION
;Purpose:
;    -to multiply 5 digit numbers
;Input:
;    -
;Output:
;    -[SI]
;Procedures:
;    -

;----------------------------------------------------------------------------

;start of the procedure: MULTIPLICATION

MULTIPLICATION PROC
    PUSHA
   
    ADD    BX, 6
    ADD    SI, 6
    PUSH    SI
    PUSH    BX
   
    MOV     BP,SP
    MOV     AX,0
    ADD    DI,9
    PUSH DI
   
M1:    MOV    AL,00H
    MOV    [DI],AL
    CMP    DI,ODH
    JE    M2
    DEC    DI

M2:    POP    DI

M3:    MOV    SI,[BP+2]
    PUSH    DI

M4:    MOV    AL,[SI]
    MOV    AH,[BX]
    MUL    AH
    ADD    [DI],AL
    MOV    AL,[DI]
    AAM
    MOV    [DI],AL
    DEC    DI
    ADD    [DI],AH
    DEC    SI
    CMP    SI,0DH
    JNE    M4
    DEC    BX
    CMP    BX,0DH
    JNE    M4
   
    POPA
    RET
MULTIPLICATION ENDP
.EXIT
;--------------------------------------------------------------------------
   

   

Share:

Assembly Program for Display back the list of numbers sorted from largest to smallest.


 PAGE 58,132
;----------------------------------------------
; DISPLAY
;
; Purpose:
;    Display back the list of numbers sorted from    
;    largest to smallest.
;----------------------------------------------

; set title and instruction set
    TITLE    DESCEND - prototype    
    .MODEL    SMALL
    .286

; set up the stack
    .STACK

;---------------------------------------------- DATA segment
    .DATA
 DESCEND db 13,10,"The numbers sorted from largest to smallest are: "
 L_DESCEND equ $-DESCEND

 MESSAGE db 13,10,"Enter up to 10 positive decimal numbers : "
 L_MESSAGE equ $-MESSAGE

 INPUT db 30 dup(?)        ;Input
 L_INPUT equ $-INPUT

;---------------------------------------------- CODE segment
    .CODE

    PAGE
;----------------------------------------------
; MAIN (main program)
;
; Purpose:
;    to descend the order of 10 digits
;
; Input:
;    10 digits
;
; Output:
;    the message is displayed on the screen
;
; Procedures:
;    -- none --
;----------------------------------------------

; Procedure: MAIN
 MAIN    PROC    FAR

; start the main program
    .STARTUP

; display the message
    MOV    BX,0001H
    LEA    DX,MESSAGE
    MOV    CX,L_MESSAGE
    MOV    AH,40H
    INT    21H

; enter 10 digits
    MOV    BX,0000H
    LEA    DX,INPUT
    MOV    CX,L_INPUT
    MOV    AH,3FH
    INT     21H
   
; display the output
    MOV    BX,0001H
    LEA    DX,DESCEND
    MOV    CX,L_DESCEND
    MOV    AH,40H
    INT    21H

; procedures
;--------------------------------------
 MOV CX,L_INPUT
 MOV SI,0h

L1:     MOV DL,INPUT[SI]
        cmp DL,39H
      JNZ L2
   
    MOV DL,INPUT[SI]
     MOV AH,2
     INT 21H

    MOV DL,20H
    MOV AH,2
     INT 21H
   

L2:     INC SI
    LOOP L1

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L3:     mov dl,INPUT[si]
        cmp dl,38h
      jnz L4
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L4:     inc si
    loop L3

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L5:     mov dl,INPUT[si]
        cmp dl,37h
      jnz L6
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L6:     inc si
    loop L5

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L7:     mov dl,INPUT[si]
        cmp dl,36h
      jnz L8
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L8:     inc si
    loop L7

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L9:     mov dl,INPUT[si]
        cmp dl,35h
      jnz L10
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L10:     inc si
    loop L9

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L11:     mov dl,INPUT[si]
        cmp dl,34h
      jnz L12
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L12:     inc si
    loop L11

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L13:     mov dl,INPUT[si]
        cmp dl,33h
      jnz L14
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L14:     inc si
    loop L13

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L15:     mov dl,INPUT[si]
        cmp dl,32h
      jnz L16
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L16:     inc si
    loop L15

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L17:     mov dl,INPUT[si]
        cmp dl,31h
      jnz L18
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L18:     inc si
    loop L17

;--------------------------------------
 mov cx,L_INPUT
 mov si,0h

L19:     mov dl,INPUT[si]
        cmp dl,0
      jnz L20
   
    mov dl,INPUT[si]
     mov ah,2
     int 21h

    mov dl,20h
    mov ah,2
     int 21h
   

L20:     inc si
    loop L19




; return to DOS
    .EXIT

; End of Procedure: MAIN
    MAIN    ENDP



;---------------------------------------------- End of program
    END
Share:

Assembly Program for LED Indicator


P1        EQU     090H
TCON     EQU     088H   
IE        EQU     0A8H

ORG 0000H                 ;entry address for 8051 RESET
LJMP MAIN                  ;by-pass int. vector table

;===================================================================================
;ISR for INT1
;INCREASE DELAY BY 0.5 SECOND
;===================================================================================
ORG 0013H                  ;INT1

CJNE A, #00000100B, NOT_EQUAL
MOV A, #1
SJMP J
NOT_EQUAL:
 INC A
 MOV R5, A
J:     
       MOV R6, #0
NXT2:  MOV R7, #0
N2:
    DJNZ R7, N2
    DJNZ R6, NXT2

RETI


;===================================================================================
;MAIN PROGRAM
;===================================================================================
ORG 0030H
MAIN:
    SETB TCON.3            ;H-to-L transition
    MOV IE, #10000100B
    MOV P1, #0FFH
     MOV A, #1

RETURN:
    CPL P1.7
    LCALL JUMP
    CPL P1.6
    LCALL JUMP
    CPL P1.5
    LCALL JUMP
    CPL P1.4
    LCALL JUMP
    CPL P1.3
    LCALL JUMP
    CPL P1.2
    LCALL JUMP
    CPL P1.1
    LCALL JUMP
    CPL P1.0
    LCALL JUMP
    mov p1, #11111111b

SJMP RETURN

;===========================================================
; DELAY (0.5 SECOND)
;===========================================================
JUMP:
MOV R5, A

DELAY:
         MOV R2,#4
NEXT:    MOV R1,#240
AGAIN1:    MOV R0, #240 
AGAIN:
DJNZ R0,AGAIN
DJNZ R1,AGAIN1
DJNZ R2, NEXT 

        MOV R3, #4
NEXT2:  MOV R4, #244
AGAIN2:
    DJNZ R4, AGAIN2
    DJNZ R3, NEXT2
DJNZ R5, DELAY

RET

;END OF DELAY

END
Share:

Assembly Program for 24 Seconds shoot clock

 
;=============================================================================================
P1     EQU   090H                    ;----- initialized seven segment display
P3     EQU   0B0H                    ;----- initialized buzzer
B      EQU   0F0H                    ;----- initialized B
;=============================================================================================

MAIN:
    MOV    R0,#24                        ;initialize R0 to 24
   
;=============================================================================================   

START:
               
    MOV    A,R0                        ;move  to the accumulator
    MOV    B,#10                        ;move the value of 10 to B
    DIV    AB                            ;divide A by B, and ans qoutient to A and remainder to B
    LCALL    DISPLAY                    ;call the pattern to start counting
    SETB    P3.5                    ;enable the 2nd digit for display
    MOV    P1,A                        ;enable the 1st digit  for display
    CLR    P3.5                        ;clear to disable the 2nd digit  display
    MOV    R4,B                        ;move the remainder in B to register R4
    MOV    A,R4                        ;move the register R4 to accumulator
    LCALL    DISPLAY                    ;call pattern
    MOV    P1,A                        ; display the second digit pattern
    MOV    R1,#0                        ;initialized R1 to 0
    MOV    R2,#0                        ;initialized R2 to 0
    MOV    R3,#7                        ;initialized R3 to 7
    CJNE    R0,#0,DELAY                ;jump to DELAY if R0 is not equal to 0
    SJMP    BUZZ                    ; if R0 is already 00, jump to BUZZER
   
;==============================================================================================

DISPLAY:                                ;subroutine for driving LED Display
    INC    A                            ;increment the current value in Accumulator
    MOVC    A,@A+PC                  ;Register Indexed Addressing mode       
    RET  
                                    ; hex form of 0 to  9
    DB    0C0H        ;0       
    DB    0F9H        ;1
    DB    0A4H        ;2
    DB    0B0H        ;3
    DB    99H            ;4
    DB    92H            ;5
    DB    82H            ;6
    DB    0F8H        ;7
    DB    80H            ;8
    DB    90H            ;9

;==============================================================================================
   
DELAY:                       
    DJNZ    R1, DELAY                 ;delay of 1 second before displaying the next pattern
    DJNZ    R2, DELAY               
    DJNZ    R3, DELAY
    DEC        R0                        ;decrementing R0
    SJMP    START

;==============================================================================================
   
BUZZ:
        MOV     R1,#500                ;initializing R1
        MOV        R2,#500

       
BUZZ_1:
   
    CLR     P3.7                     ;setting 1 for output port P3.7
    DJNZ    R1,BUZZ_1                ;setting delay for setting port P3.7 to zero

BUZZ_2:
   
    SETB     P3.7                    ;setting 0 for output port P.3.7
    DJNZ    R2,BUZZ_2                ;setting delay for setting port P3.7 to one
   
    SJMP     BUZZ                    ;infinite loop for enabling buzzer

   
END

;===============================================================================================
Share:

Our Sponsor

Popular Post