GetHex Program in Assmebly using MASM

liunx

Guest
I have to write a function GetHex which has to read and echo hex digits from the keyborad and converts it into a word, which than returns its value in ax. I have to test for 4 hex digits. I have to use shift function somehow <img src="http://static.dreamincode.net/forums/style_emoticons/default/blink.gif" style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> I am not to sure about using the shift function<br /><br />If someone can help me. it would be great.!!!!!!<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->INCLUDE F:\cs17\PCMAC.INC<br /><br />        .MODEL  SMALL<br />        .586<br /><br />        .STACK  100h<br /><br />        .DATA<br />Count    DB    4<br /><br />        .CODE<br />    PUBLIC    GetDec<br /><br />GetDec    PROC<br /><br />       ; ax not saved since it stores the return value<br />    push    bx<br />    push    cx<br />    push    dx<br /><br /><br /> <br />ReadLoop:<br />        _GetCh<br /><br />        cmp     al, '0'        ; Is character a digit?<br />        jb      Done<br /><br />        cmp     al, '9'<br />        ja      Done<br /><br />        mov     ah, 0<br />        sub     al, '0'        ; '0' = 48 (al = al - 48)<br /><br />        xchg    ax, bx         ; Add number to total<br />        mul     cx<br />        add     bx, ax<br />        <br />        <br />    dec    Count<br />        jmp     ReadLoop<br /><br /><br /><br /><br />Positive:<br />        mov     ax, bx         ; Returned value in ax<br /><br />    pop    dx<br />    pop    cx<br />    pop    bx<br /><br />        ret<br />GetDec    ENDP<br /><br />        END<!--c2--></div><!--ec2-->
</div>
 
Back
Top