UMBC CMSC 211 |
We will use three library calls to do the work for us now. These call handle signed numbers.
.CODE EXTRN GetDec : NEAR, PutDec : NEAR, PutHex : NEAR ProcName PROC etc.Then when we link the program, we must use:
The alternative form is:
;; DECTOHEX .ASM - A program which requests input of a decimal number from the ;; keyboard and then prints its hex representation ;; ;; Must be linked using: ;; link DECTOHEX,,,UTIL ;; INCLUDE PCMAC.INC .MODEL SMALL .STACK 100h .DATA CR EQU 13 LF EQU 10 Prompt DB 'Enter decimal number: $' OutMsg DB 'The hex equivalent is $' SaveAX DW ? .CODE EXTERN GetDec : NEAR , PutHex : NEAR DecToHex PROC mov ax, @data mov ds, ax _PutStr Prompt call GetDec; ;ax := decimal number from keyboard mov SaveAX, ax ;Save ax in variable _PutStr OutMsg mov ax, SaveAX ;Restore AX call _PutHex ;Display input has hex _Putch 'H', CR, LF ;Display trailing 'H' to show its a hex ; value and start a new line _Exit 0 ;Return to DOS DecToHex ENDP end DecToHex
mov al, dh mov ah, 0 ; Extend to a word, assuming it is not signed call PutDec ; Show it!