Search code examples
assemblyx86dosdosbox

How to print the values after using the push and pop stack


I have a question about assembly.

MOV AX,50
MOV BX,60

PUSH AX
PUSH BX

POP AX

The value of AX is 60. My question is how can I print AX. Since all I know is:

MOV AH,02
MOV DL,41
INT 21H

I am having a difficulty in printing 16-bit registers.


Solution

  • Your question is a duplicate of Displaying numbers with DOS. I'm sure someone else will close it as such!

    Not mentioned in the answer from the link, is that for numbers that stay below 100, so with less than 3 digits, you could use next code:

    ; IN (al=[0,99])
      aam
      add  ax, "00"
      mov  dx, ax
      cmp  dh, "0"
      je   OneDigit
      xchg dl, dh    ; First show the 'tens'
      mov  ah, 02h   ; DOS.PrintCharacter
      int  21h
      xchg dl, dh    ; Next show the 'ones'
    OneDigit:
      mov  ah, 02h   ; DOS.PrintCharacter
      int  21h
    

    The aam instruction divides AL by 10 and stores the quotient in AH and the remainder in AL.
    add ax, "00" turns both numbers into characters that you can display on the screen.
    The cmp dh, "0" je OneDigit exists so you don't have to look at an 'ugly' prepended zero for numbers less than 10.