The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: Vix on April 24, 2005, 06:53:53 PM

Title: MASM
Post by: Vix on April 24, 2005, 06:53:53 PM
Can anyone please tell me how I can print the value inside register ax I mean can I do it
I know that int 21h is used for it but if I use

mov ah, 02h
int 21h

it will print out value of registar dl
Can i transfer data from ax to dl

Title: Re: MASM
Post by: AeroASM on April 24, 2005, 07:31:03 PM
int 21h function 02h does not print out the value of dl. It prints out the ascii character whose ascii code is in dl.

Therefore you need to generate the ascii values for each hexadecimal digit. One hexadecimal digit = four bits: therefore

1. Take four bits
2. convert it to the correct hexadecimal digit (0-9,A-F)
3. Print it!
4. Take the next four bits
5. repeat 2-5
Title: Re: MASM
Post by: thomasantony on April 25, 2005, 04:56:55 AM
Or you can just add 30h to the value to get the decimal value and print it

Thomas :U
Title: Re: MASM
Post by: AeroASM on April 25, 2005, 06:37:46 AM
Not if it is more than one decimal digit
Title: Re: MASM
Post by: guesehsaio on May 09, 2005, 07:35:17 AM
this is  my  stupid method......
it's can print eax...

PRINT_AX        PROC    NEAR
      PUSH    AX
      ADD     DL,30H
      CMP     DL,'9'
      JBE     OK
      ADD     DL,7
OK:             MOV     AH,2
      INT     21H
      POP     AX
      RET
PRINT_AX        ENDP
;***********************************************************
print_ax_1      proc near
         
      MOV     CL,4
      MOV     DL,AL
      SHR     DL,CL
      CALL    PRINT_AX
      MOV     DL,AL
     
      AND     DL,0FH
      CALL    PRINT_AX
      MOV     DL,AH
      SHR     DL,CL
      CALL    PRINT_AX
      MOV     DL,AH
 
      AND     DL,0FH
      CALL    PRINT_AX
      ret
print_ax_1      endp
;***************************************************************
print_ax_2     proc near
      MOV     CL,4
      MOV     DL,AH
      SHR     DL,CL
      CALL    PRINT_AX
      MOV     DL,AH
      AND     DL,0FH
      CALL    PRINT_AX
      MOV     DL,AL
      SHR     DL,CL
      CALL    PRINT_AX
      MOV     DL,AL
      AND     DL,0FH
      CALL    PRINT_AX
      ret
print_ax_2      endp

;**************************************************************
Swap_Eax proc near   
    ;push eax
    BSWAP eax             
    call print_ax_1   
    BSWAP eax
    ;pop eax                   
    call print_ax_2   
    ret
Swap_Eax endp
Title: Re: MASM
Post by: Vortex on May 10, 2005, 05:21:16 PM
PrintDec procedure by MichaelW:


.model small,stdcall

PrintDec PROTO :WORD

.stack
.code
start:
xor cx,cx ; set cx to 0
@@:
inc cx ; increment cx
push cx ; preserve cx as it's used by PrintDec
invoke PrintDec,cx
mov ah,2
mov dl,13
int 21h ; put CR+LF
mov ah,2
mov dl,10
int 21h
pop cx
cmp cx,10 ; Is cx equal to 10 ?
jne @b  ; If not jump back to process cx
mov ah,04Ch
int 21h

PrintDec PROC numb:WORD
mov ax,numb   
;
   ; Init divisor.
mov bx,10
   ; Zero digit counter.
mov cx,0
@@:
   ; Zero MSW of dividend.
mov dx,0
   ; Divide value by 10.
div bx
   ; Push remainder.
push dx
   ; Increment digit count.
inc cx
   ; Repeat if quotient > 0.
or ax,ax
jnz @B
@@:
   ; Pop digit off stack.
pop dx
   ; Convert to ascii.
add dl,30h
   ; Display.
mov ah,2
int 21h
   ; Repeat CX times.
loop @B
ret
PrintDec ENDP

END start