1

It's might sound extremely dumb(and it's probably extremely dumb) but when I copy a value from a variable to an register, I noticed that he copying it like a symbol(probably have to do something with the ASCII code?), but I need it to be as a number instead. what I tried to do:

    mov ah,[byte ptr playerSize]
    mov [statusBar+17],ah

and after moving to ah the value in playerSize, ah containing kind of symbol, and when I try to move it back to the statusBar, the symbol getting moved and not the number.

Thanks for any kind of help :)

Cake
  • 21
  • 1
  • 6
  • You need to convert number into string (in order to display it), or from string to number (when captured from keyboard, for example). My procs `string2number` and `number2string` will help you : http://stackoverflow.com/questions/30243848/assembly-x86-date-to-number-breaking-a-string-into-smaller-sections/30244131#30244131 . – Jose Manuel Abarca Rodríguez May 30 '16 at 13:52
  • @JoseManuelAbarcaRodríguez Thanks you so much, I used it and it's helped me so much! :D – Cake May 30 '16 at 14:17

1 Answers1

0

It's not symbol, it's the actual number, for example 32, when player size is 32.

Your problem is, that you want to show the number in human formatting (decimal number). Usually any font rendering function uses some kind of character encoding, common ones (a programmer should know) are ASCII and UTF-8 (first 127 codes are basically same as ASCII).

So if you want the font rendering to display "A", you have first to know what kind of number encodes big A (as for CPU there are just numbers from 0..(2^num_of_bits)-1, CPU has no idea what is "A". In ASCII and UTF-8 the big "A" is encoded as number 65, so memory consisting of four bytes "65, 65, 65, 0", entered as input into some routine, which displays zero terminated string, will display "AAA".

Now I will suppose your "statusBar" is ASCII zero terminated string, you are displaying by some means... ? Probably.

So you want number 32 (player size) convert to string like 0x20, 0x20, 0x33, 0x32 (" 32") and store it at statusBar+17 to statusBar+20 bytes in memory.

If you have function to render the status bar, you probably have somewhere also number formatting function, search your API.

Otherwise do your own, just check the desired encoding (ASCII conversion is simple, digit x has ASCII code x+0x30), and divide the number by 10, encode remainder, put it at end of string, move left by one, continue till result of divide is zero, then fill up rest of string with spaces.

Ped7g
  • 16,236
  • 3
  • 26
  • 63
  • Thanks for the information, I'll keep it in my head! – Cake May 30 '16 at 14:18
  • Try to read something about old DOS text modes (CGA/EGA/VGA), and about ASCII, that was simple way to display ASCII text. Then imagine doing the same in graphics mode on your own, per pixel. Soon you will understand why encoding was used for strings. – Ped7g May 30 '16 at 14:41