Assembly Language Programs
1) Write an ALP 16 convert HEX number, into its ASCII equipvalent.
Ans:-
.MODEL SMALL
.STACK 100H
.DATA
HEX DB 7h ; the HEX number to convert
ASCII DB 6 DUP ('$') ; allocate space for 6 ASCII characters
.CODE
MAIN PROC
MOV AX, @DATA ; initialize data segment
MOV DS, AX
MOV BL, HEX ; load HEX number into BL register
; convert first nibble to ASCII character
AND BL, 0FH ; mask off upper nibble
ADD BL, 30H ; convert to ASCII
CMP BL, 3AH ; check if character is between '0' and '9'
JBE WRITE_CHAR ; if yes, jump to WRITE_CHAR
ADD BL, 7H ; if no, add 7 to get 'A'-'F'
WRITE_CHAR:
MOV ASCII, BL ; store first ASCII character in memory
; convert second nibble to ASCII character
MOV BL, HEX ; reload HEX number into BL register
SHR BL, 4 ; shift right to get upper nibble
AND BL, 0FH ; mask off lower nibble
ADD BL, 30H ; convert to ASCII
CMP BL, 3AH ; check if character is between '0' and '9'
JBE WRITE_CHAR2 ; if yes, jump to WRITE_CHAR2
ADD BL, 7H ; if no, add 7 to get 'A'-'F'
WRITE_CHAR2:
MOV ASCII+1, BL ; store second ASCII character in memory
; display ASCII characters
MOV AH, 9 ; set output function
MOV DX, OFFSET ASCII ; load offset of ASCII string
INT 21H ; display string
MOV AH, 4CH ; exit program function
INT 21H ; return control to operating system
MAIN ENDP
END MAIN
2) Write an ALP to count number of 1 in 16-bit number.
Ans:-
---------------------------
Thank You !
Comments
Post a Comment