0

I'm currently working on a project for school in x86 assembly. We are coding the retro game Breakout.

We render the game in video mode 13h. The problem is that we would like to display the current score of the player on the screen. This is a procedure we have for printing a $-terminated string to the screen:

PROC displayString
    ARG @@row:DWORD, @@column:DWORD, @@offset:DWORD
    USES EAX, EBX, EDX
    MOV EDX, [@@row] ; row in EDX
    MOV EBX, [@@column] ; column in EBX
    MOV AH, 02H ; set cursor position
    SHL EDX, 08H ; row in DH (00H is top)
    MOV DL, BL ; column in DL (00H is left)
    MOV BH, 0 ; page number in BH
    INT 10H ; raise interrupt
    MOV AH, 09H ; write string to standard output
    MOV EDX, [@@offset] ; offset of '$'-terminated string in EDX
    INT 21H ; raise interrupt
    RET
ENDP displayString

The problem is that I can't find a solid way to convert our integer into a dollar terminated string so that this procedure can print it on the screen.

Can anyone offer suggestions on how to convert a value to a $ terminated string?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
nTn
  • 11
  • 1
  • You will have to write your own code to convert and integer to ASCII. You can repeatedly divide a value by 10 to get each digit (in reverse order) and then store those digits to string. – Michael Petch Dec 17 '19 at 11:04
  • Thanks for the reply! That was my first thought. The problem is in combining those digits to a string, and then even adding the 13,10 and $ sign to make it terminated. – nTn Dec 17 '19 at 11:07
  • Why would you need to add a CarriageReturn and NewLine to the string when printing a score? – Michael Dec 17 '19 at 12:26
  • [Assembly 8086 | Sum of an array, printing multi-digit numbers](//stackoverflow.com/q/40503119) includes an answer that does int->string into a buffer and appends a `$` for int 21h/AH=9 – Peter Cordes Dec 17 '19 at 17:07
  • 1
    A MASM/TASM version with a separate function for printing EOL, and a function to convert an unsigned value in AX as a decimal string can be found here: https://pastebin.com/xMimx36K – Michael Petch Dec 17 '19 at 18:26

0 Answers0