Hello. This code im going to show you, is supposed to allow one to view the contents of a register or memory location. Im using it on masm and it compiles ok. Although i dont know where the print routine displays register contents. Any words would be a big help, thank you.


; Assemble options needed: none

.MODEL small



          mov ax, 0FFFFh     ; Load AX with something distinctive.
          call print_word    ; Print the contents of the AX register.

          mov ax, 4c00h      ; Prepare to exit.
          int 21h            ; Exit.

print_word PROC              ; MS-DOS version.
          push dx            ; Save all registers that are used.
          push cx
          push bx
          push ax

          mov dx, 4          ; Loop will print out 4 hex characters.
          push dx            ; Save the loop counter.
          mov cl, 4          ; Rotate register 4 bits.
          rol ax, cl
          push ax            ; Save current value in AX.

          and al, 0Fh        ; Mask off all but 4 lowest bits.
          cmp al, 10         ; Check to see if digit is 0-9.
          jl decimal         ; Digit is 0-9.
          add al, 7          ; Add 7 for Digits A-F.
          add al, 30h        ; Add 30h to get ASCII character.

          mov dl, al
          mov ah, 02h        ; Prepare for interrupt.
          int 21h            ; Do MS-DOS call to print out value.

          pop ax             ; Restore value to AX.
          pop dx             ; Restore the loop counter.
          dec dx             ; Decrement loop counter.
          jnz nexthex        ; Loop back if there is another character
                             ; to print.

          pop ax             ; Restore all registers that were used.
          pop bx
          pop cx
          pop dx
print_word ENDP

END Start
8 Years
Discussion Span
Last Post by NotNull

The print routine is translating the value of AX into
ASCI characters and printing them using Function 2 of the
MS-DOS Function Request Interrupt.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.