Wednesday, 13 March 2013

Assembly Code to get BCD code

Assembly Code to get BCD code

;DATA PART
DATA SEGMENT
    N DB 34H,35H,24H ; SIMILART TO "45$"
DATA ENDS                              
;Code Part
CODE SEGMENT
    ASSUME CS: CODE, DS: DATA  
 

    ;get Address of N in BX register
    MOV BX, OFFSET N    
   
    ;fetch first byte to AL register           
    MOV AL, [BX]
    ;Shift bits to left by 4 positions
    SHL AL, 4               
    ;Save content of AL in DL register
    MOV DL, AL                     
   
    ;fetch second byte to AL register     
    MOV AL, [BX+1]                  
    ;Make left most 4 bits to 0
    AND AL, 0FH               
                 
    ;Add first byte in DL and Second Byte in AL
    ; to get packed BCD Code
    OR AL, DL              
   
    ;to print packed BCD code move it to DL register
    MOV DL, AL                                     
   
    ;Call DOS output interrupt                
    MOV AH, 02H
    INT 21H
CODE ENDS

No comments:

Post a Comment