Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/09/11 11:10
Modified:
  08/09/11 11:13

Read: times


 
#183279 - Actually BCD!!
Responding to: ???'s previous message
Per Westermark said:
Your new code presents the number in hexadecimal, i.e. base 16.


The conversion routine that Cammack showed on this second time around is actually a function that would accept the byte in the entry A register and convert it from BCD to a two digit ASCII value in the range from "00" to "99". The code as shown makes the strict assumption that the binary value of upper and lower nibbles of the A register (bits 7-4 and bits 3-0 respectively) do not exceed 1001B (binary representation).

If the intent is to show the value as a hexadecimal where the binary value of each nibble of the A register is to be interpreted as its whole range from 0000B through 1111B then there needs to be extra code added to the conversion to make sure that the values 1010B through 1111B come out as "A" through "F". Here is an example of the conversion routine that takes care of this extra step so that it is an actual hexadecimal conversion routine. Note that the shown code only takes care of one nibble and in an actual application would be called two times to handle a full byte value as shown in the second routine.

;***************************************************
;NAME: DISP_NIBH and DISP_NIBL
;   Routine to convert a binary nibble to hex
;   and send the value to display as a single
;   digit hex ascii value.
;
;   Entry A = binary nibble value to display
;---------------------------------------------------

DISP_NIBH:
        SWAP    A                   ; put the upper nibble to low position
;
DISP_NIBL:
        ANL     A, #0FH             ; mask to single nibble
        ADD     A, #30H             ; convert to ascii
        DA      A
        MOV     C, ACC.6            ; convert to A-F
        ADDC    A, #0
        CALL    DISP_CHAR
        RET

;***************************************************
;NAME: DISP_BYTE
;   Routine to convert a binary byte to hex
;   and send the value to display as two digit
;   hex ascii value.
;
;   Entry A = binary byte value to display
;---------------------------------------------------

DISP_BYTE:
        PUSH    ACC
        CALL    DISP_NIBH           ; display the upper nibble
        POP     ACC
        CALL    DISP_NIBL           ; display the lower nibble
        RET



Michael Karas


List of 17 messages in thread
TopicAuthorDate
need help to display timer count on hyperterminal and LED'S            01/01/70 00:00      
   Attention to Details            01/01/70 00:00      
      divide by 10            01/01/70 00:00      
         Hundredth digit is quotient of division by 100            01/01/70 00:00      
            thanks            01/01/70 00:00      
               Debugged with pen and paper?            01/01/70 00:00      
                  Debugged            01/01/70 00:00      
                     Decimal or hexadecimal?            01/01/70 00:00      
                        decision            01/01/70 00:00      
                           So take up the challenge then            01/01/70 00:00      
                              agreed            01/01/70 00:00      
                        Actually BCD!!            01/01/70 00:00      
   Oh Details Details            01/01/70 00:00      
      update            01/01/70 00:00      
         Issues            01/01/70 00:00      
            better to check before sending            01/01/70 00:00      
               Even Better....            01/01/70 00:00      

Back to Subject List