To write 8086 Assembly Language Program to Find Square Root of a hexadecimal number.
Answer:
; SQUARE ROOT OF A NUMBER
MODEL SMALL
.STACK 100
.DATA                                                       ; Data segment starts
    NUM1 DW 0019H                    ; Initialize num1 to 0019
    SQRT DW 01 DUP (?)                 ; Reserve 1 word of uninitialised data space to offset sqrt
.CODE                                          ; Code segment starts
START:
               MOV AX,@DATA               ;Initialize data segment
               MOV DS,AX   
               MOV AX,NUM1               ;Move the number(num1) to AX
               XOR BX,BX                 ;XOR is performed and result is stored in BX
               MOV BX,0001H              ;Initialize BX to 0001H
               MOV CX,0001H              ;Initialize CX to 0001H
LOOP1: SUB AX,BX                 ;AX=AX-BX
               JZ LOOP2                  ; If zero flag is zero jump to loop2
               INC CX                    ; Increment CX by 1
              ADD BX,0002H              ;BX=BX+0002H
              JMP LOOP1                 ; Jump to loop1
              INC CX                    ; Increment CX by 1
LOOP2: MOV SQRT,CX                ; Store result
               INT 03H                                      ; halt           
END START
INPUT:                          
  NUM1 = 0019 H (25 IN DECIMAL)      
  NUM1 = 0090 H (144 IN DECIMAL)        
OUTPUT:
  RES = 0005H
  RES = 000CH
_________________________________________________________________
AIM: To write 8086 Assembly Language Program to Find Number of one’s & zero’s in a hexadecimal number.
Answer:
MODEL SMALL
.STACK 100
.DATA                                            ; Data segment starts
  NUM DW 0F0F0H                   ; Initialize num to F0F0 H
  ONES DB ?                            ; Reserve 1 byte for storing number of zeros
  ZEROS DB ?                       ; Reserve 1 byte for storing number of ones      
.CODE                                            ; Code segment starts
START:
    MOV AX,@DATA                    ;Initialize DS
    MOV DS,AX
    MOV CL,10H                     ;Initialize CL to 10H
    MOV BX,0000H                  ;Initialize BX to 0000H
    MOV AX,NUM                     ;Move contents of num to AX
 UP:
    SHL AX,1                          ;Shift the contents of AX left once
    JC AHEAD                           ; If CF=1 jump to label ahead
    INC BL                             ; Increment BL by 1
    JMP DOWN                       ; Jump to the label down
AHEAD:
    INC BH                            ; Increment BH by 1
DOWN:
    DEC CL                             ; Decrement CL by 1
    JNZ UP                            ; If zero flag is not 0 jump to label up
    MOV ONES,BH                    ;Move contents of BH to ones
    MOV ZEROS,BL                   ;Move contents of BL to zeros
    INT 03H                                ; Halt
END START                  
INPUT:                                  
   NUM = 0F0F0 H (0000 1111 0000 1111 0000 b)    
OUTPUT: 
 ONES = 08 H
 ZEROS = 08 H
____________________________________________________________________
AIM: To write 8086 Assembly Language Program to Find Factorial of a hexadecimal number.
Answer:
; This ALP will find factorial from 01 H to 08 H
MODEL SMALL
.STACK 100
.DATA                                                ; Data segment starts
     NUM DW ?            
     RES DB 1H
    FACT DW ?            
.CODE                                             ; Code segment starts
 START:
         MOV AX,@DATA                ; Initialize DS
         MOV DS,AX
         MOV AH,01                  ; Move 01 to AH to take input at runtime
         INT 21H                        ; Dos interrupt
         AND AX,000FH               ; Logical AND of AX,000f and stores in AX
         MOV NUM,AL                ; Move contents of AL to val1
         MOV CX,AL                  ; Move contents of AL to CL
         MOV AX,RES                 ; Move contents of res(1) to AX
  M:
         MUL CX                         ; AX = AX*CX
         LOOP M                         ; Decrements CX by 1 continues multiplication until CX is 0
         MOV FACT,AX                ; Value of AX is moved to fact
         INT 03H                                             ; Halt
END START
       
     
     
     
     
INPUT                         
     8 (DURING RUNTIME)          
OUTPUT:
       FACT =  D980  H
_________________________________________________________________
AIM: To write 8086 Assembly Language Program to Convert BCD to 7-Segment display using lookup table.
Answer:
MODEL SMALL
.STACK 100
.DATA                                                                       ; Data segment starts and defines array A having
                                                                                 ; Equivalent 7 segment codes
                      
      A DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH
      C EQU 06                                                          ; BCD number which is to be converted
      7SEG DB ?                                                        ; 7 segment code
.CODE                                                                       ; Code segment starts
START:
      MOV AX,@DATA                                           ; Initialize data segment       
      MOV DS,AX
      MOV BX,OFFSET A                                        ; Moves the starting address of A to BX    
      MOV AL,C                                                        ; Move C value to AL register
      XLAT                                                                 ; It i'll add [BX+AL] i.e. 0000 + 06 = 0006 H
     MOV 7SEG,AL                                                  ; Store the result   
      INT 03H                                                             ; Halt
END     START
   
                     
                     
INPUT:
   C = 06 H
OUTPUT:
  AL = 7D H
You might be also interested in:
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI
:: MASM 611 SOFTWARE
::  bit reversal and sorting programs
1 comment:
Find Square Root of a hexadecimal number in assembly language in 8051 microcontroller.
Post a Comment