; ;**************************************************************************** ; ; Purpose: ; Conversion from 2 digit HEX to binary ; ; ; Date: ; 08/03/99 ; ; Author: ; Umar Tsani Abdurrahman (utsania@yahoo.com) ; ; Modifications: ; ; ; Processor: ; Generic 8051 ; ; Assembler: ; ASM51 ; ; Dependencies: ; None ; ; Files: ; None ; ; Philosophic: ; ;**************************************************************************** ; Free usage without modification ;**************************************************************************** ; Description: ; Converts Hex string to binary ; ; Entry Requirements: ; Acc contains LSB digit to convert ; B Contains MSB digit to convert ; (all DIGITS IN CAPITAL:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) ; On Exit: ; A contains Conversion Result Binary Value ; ; Usage Example: ; convert hex value : 5A (HEX) to binary ; Mov a,#'A' ;LSB ; mov b,#'5' ;MSB ; lcall hex2bin ; ; the result in A is 'Z' (binary) ; hex2bin: ;lsb part, this process subtract the value so LSB will reflect binary value of LSB digit subb a,#'0' cjne a,#9+1,h2bkc1 h2bkc1: jc h2bkc2 subb a,#7 h2bkc2: clr c push acc ;put the result on stack mov a,b ;do the MSB part ;msb part subb a,#'0' cjne a,#9+1,h2bkc3 h2bkc3: jc h2bkc4 subb a,#7 h2bkc4: clr c mov b,#010h ;16 times the result is the MSB mul ab mov b,a ;Put the result on B pop acc ;put back LSB add a,b ;lsb+msb ;result on a ret