*************************************************************** * * * Module ID: SHOWNUMB.LIB By: GLH/W6BSK * * Last Updated: 28 Apr 85 * * Function : Binary, hex & dec Version : 1.00 * * display routine * * Entry: HL has 16 bit binary value * * Exit : No exit values. * * * *************************************************************** ; Display values from HL co6bin: mov a,h ; Get byte in H call co8bin ; and display it. mov a,l ; Do same for L co8bin: push b ; Save the BC entry values mvi c,8 ; Set count co8bi1: ral mov b,a ; Save remainder mvi a,'0' ; Load ASCII 0 jnc co8bi2 ; and display if no carry mvi a,'1' ; else display ASCII 1 co8bi2: call conout ; Dump the character mov a,b ; Restore the remainder dcr c ; update the count jnz co8bi1 ; and continue until done. pop b ; Restore entry values ret ; Binary display done co6hex: mov a,h ; Load high byte call co8hex ; and dump it. mov a,l ; Do same for low. co8hex: push psw ; Save entry values ani 0F0h ; Strip low nibble rrc rrc ; Swap nibbles rrc rrc call co4hex ; Display value as hex pop psw ; Restore entry value ani 0fh ; Strip high nibble co4hex: cpi 10 ; Test if 0-9 jm co4he1 ; Yes, use as is adi 7 ; No, convert to A-F co4he1: adi '0' ; Make value ASCII jmp conout ; and output it. co8dec: push h ; Stack entry values mvi h,0 ; Enter with value in A mov l,a ; Clear high byte, set low. jmp co6de1 ; Display single-byte value. co6dec: push h ; Entry for 16-bit number co6de1: push d push b Š xra a ; Clear leading-zero flag sta zflag mvi c,5 ; Count for 5 characters shld value ; Save current value lxi h,tthou ; Point to ten thou divider shld index ; and save it. co6de2: lhld index ; Get current divider mov e,m inx h ; and put in DE mov d,m inx h ; Move to next divider shld index ; Character starts at zero mvi b,0 lhld value ; Subtract divider until co6de3: dad d ; borrow occurs jnc co6de4 shld value inr b ; Keep count of subs jmp co6de3 co6de4: mov a,b ; Get count value ora a ; and test for inhibit jz co6de7 ; No div, inhibit leading zeros sta zflag ; Is, flag first non-zero co6de5: mov a,b ; Get count and adi '0' ; convert to ASCII co6de6: call conout ; Display character dcr c ; update character count jnz co6de2 ; and get next until done. pop b pop d pop h ret co6de7: lda zflag ; Test for suppression of ora a ; leading zero. jnz co6de5 ; No, display zero mov a,c ; Test for last character. cpi 1 ; All zeroes? jz co6de5 ; Yes, display them. mvi a,' ' ; No, dump a space jmp co6de6 zflag ds 1 ; Leading zero flag value ds 2 ; Current value index ds 2 ; index into different tthou dw 0-10000 ; "dividers" uthou dw 0-1000 hunds dw 0-100 tens dw 0-10 units dw 0-1