1704 ;;Conv.MAC ;;==== Various conversion routines ;;TITLE Dec2Hex.MAC ;;==== converts decimal value in 'buff' to HEX and stores it in DX ;;-------------------------------------------------------------------------- dec2hex MACRO buff LOCAL convert,ready push ax push bx push cx push di mov di,OFFSET buff sub ax,ax sub dx,dx sub bx,bx convert: mov bl,byte ptr[di] inc di cmp bl,0 je ready sub bl,030h mov cx,0ah mul cx add ax,bx jmp convert ready: mov dx,ax ;;Place result in DX pop di pop cx pop bx pop ax ENDM ;;------------------------------------------------------------------------- ;;===== Hex2Dec.MAC ;;====== Converts value in DX to Decimal ;;--------------------------------------------------------------------- Hex2Dec MACRO buff LOCAL Kvot_0,Slut,fill_buf,Go_On,Over_fill push ax push cx push di call fill_buf mov di,OFFSET Buff+1 cmp dx,0000h jnz Kvot_0 mov byte ptr[di],'0' ;;¸tminstone ETT v„rde jmp Slut Kvot_0: mov ax,dx ;;Hex-talet -> AX mov dx,0000h ;;Nollst DX ('Rest') mov cx,0ah ;;10 -> CX ('N„mnare') div cx ;;Operation AX/CX ;;Kvot -> AX och Rest -> DX xchg ax,dx ;;Kvot -> DX, Rest -> AX add al,30h ;;HEX -> ASCII mov [di],al ;;ASCII-v„rdet sparas inc di ;;N„sta cell pekas ut cmp dx,0000h ;;Kvoten i div = 0 ? jnz Kvot_0 ;;Forts„tt tills kvot = 0 Slut: jmp Over_fill fill_buf PROC NEAR mov di,OFFSET Buff mov ax,0000h Go_On: mov byte ptr[di],al inc di inc ah cmp ah,07h jnz Go_On ret fill_buf ENDP Over_fill: pop di pop cx pop ax ENDM ;;-------------------------------------------------------------------------- ;;TITLE Hex2Bin.MAC ;;===== Writes out value in DX in binary form ;;------------------------------------------------------------------------ Hex2Bin MACRO LOCAL Next_Bit,Bit_0,No_Spc,Quit push ax push bx push cx mov ax,dx ;;Word -> ax mov cl,0fh ;;Bit Counter mov bx,8000h ;;Mask which is shifted right ;;for each turn Next_Bit: and ax,bx ;;Do masking cmp cl,00h ;;Bit 0? jz Bit_0 ;;if so, don't shift shr ax,cl ;;Make result 0/1 Bit_0: add al,30h ;;Against ASCII push dx ;;Save DX temporarily mov dl,al ;;Write bit mov ah,02h int 21h ;;------ Space Bit 7 & Bit 8 ----------------------------------- cmp cl,08h jnz No_Spc mov dl,' ' mov ah,02h int 21h ;;---------------------------------------------------------------- No_Spc: pop dx ;;Now we can fetch DX dec cl ;;Decrement bit counter cmp cl,-1 ;; = -1? jz Quit ;; if so, quit shr bx,1 ;;Shift mask 1 step right mov ax,dx ;;Word -> AX jmp Next_Bit Quit: pop cx pop bx pop ax ENDM ;;===================================================================== ;;------------------------------------------------------------------------- ;;TITLE Bin2Hex.MAC ;;====== Rutinen h„mtar bin„ra tecken fr†n 'Bin_buf', konverterar till ;;====== HEX och sparar v„rdet i DX. ;;====== Tecknen h„mtas fr†n dataareans topp och g†r ner†t. ;;====== Buffern skall b†de b”rja och sluta med 00. ;;------------------------------------------------------------------------- Bin2Hex MACRO bin_buf LOCAL Next_Adress,Next_Char,No_add,Klart,Slut push ax push cx push di mov di,OFFSET (bin_buf+1) ;;--------- H„r best„ms bufferns storlek ----------------------- Next_adress: mov dl,[di] ;;H„mta tecken cmp dl,00h ;;0? jz Klart inc di jmp Next_Adress Klart: dec di ;;----- Konvertering till Hextal, l„ggs i DX ---------------------------- mov dx,0000h ;;Nollst„ll DX mov cx,0001h ;;Initiera multiplicerare Next_char: mov al,[di] ;;Tecken -> DL i ordn ;;MSB -> LSB cmp al,00h jz Slut sub al,30h cmp al,0 jz No_add add dx,cx No_add: dec di ;;Peka p† n„sta tecken sal cx,1 jmp Next_Char Slut: pop di pop cx pop ax ENDM ;;--------------------------------------------------------------------------- . 0