
: void DEOLN() {
    DL = 0x0D;
    AH = 2;
    $int 21h
    DL = 0x0A;
    AH = 2;
    $int 21h
}



void DWRITE() {
    SI = AX;
DWRITE_LOOP:
    $lodsb
    $cmp AL, 0
    $jz DWRITE_EXIT
    $cmp AL, 0x0A
    $jne DWRITE_CHAR
    DL = 0x0D;
    AH = 2;
    $int 21h
    AL = 0x0A;

DWRITE_CHAR:
    DL = AL;
    AH = 2;
    $int 21h
    $jmp short DWRITE_LOOP

DWRITE_EXIT:
}



void DWRITELN() {
    DWRITE();
    DEOLN();
}


: void DWRITEHEXBYTE() {
    CX=2;
    loop(CX){
        $rol AL,4
        $push AX
        AL&=0xF;
        $CMP AL,10
        $sbb AL,0x69
        $das
        DX=AX;
        AH=2;
        $int 21h
        $pop AX
    }
}


: void DWRITEHEXWORD() {
    CX=4;
    loop(CX){
        $rol AX,4
        $push AX
        AL&=0xF;
        $CMP AL,10
        $sbb AL,0x69
        $das
        DX=AX;
        AH=2;
        $int 21h
        $pop AX
    }
}


: void DWRITEHEXDWORD() {
    CX=8;
    loop(CX){
        $rol EAX,4
        $push EAX
        AL&=0xF;
        $CMP AL,10
        $sbb AL,0x69
        $das
        DX=AX;
        AH=2;
        $int 21h
        $pop EAX
    }
}


: void DWRITEDECWORD() {
    $ CMP AX,10000
    $ JNB DOWN1
    $ CMP AX,1000
    $ JNB DOWN2
    $ CMP AX,100
    $ JNB DOWN3
    $ CMP AX,10
    $ JNB DOWN4
    $ JMP SHORT DOWN5
DOWN1:
    DX = 0;
    CX = 10000;
    $DIV CX
    $CALL NEAR DOWN5
DOWN2:
    DX = 0;
    CX = 1000;
    $DIV CX
    $CALL NEAR DOWN5
DOWN3:
    CL = 100;
    $DIV CL
    DL = AH;
    $CALL NEAR DOWN5
DOWN4:
    $AAM
    DL=AL;
    AL=AH;
    $CALL NEAR DOWN5
DOWN5:
    $push DX
    DL = AL + '0';
    AH = 0x2;
    $int 0x21
    $pop AX
}



void DWRITELNDECWORD() {
    DWRITEDECWORD();
    DEOLN();
}

void DWRITELNHEXDWORD() {
    DWRITEHEXDWORD();
    DL = 'h';
    AH = 0x2;
    $int 0x21
    DEOLN();
}


void DWRITELNHEXWORD() {
    DWRITEHEXWORD();
    DL = 'h';
    AH = 0x2;
    $int 0x21
    DEOLN();
}
