Question

I have written a simple small assembly program in MASM but the output I am getting is unexpected and is prefixed by 3. Like i have entered 12345 on displaying it shows output as

31 32 33 34 35

Where as if I don't take input from user and hard code it like mystring byte 1,2,3,4,6 - It shows output like 01 02 03 04 06

Help me in understanding this behavior - Thanks in advance

Here is program code:

INCLUDE Irvine32.inc

.data
disp byte "Enter String : ",0
mystring byte 5 dup(?)

.code 
main PROC
mov edx,offset disp
call writestring
mov edx, offset mystring
mov ecx, 50
call ReadString
mov esi, offset mystring
mov ecx, lengthof mystring
mov ebx, TYPE mystring
call dumpmem

exit
main ENDP
END main
Was it helpful?

Solution

You are dumping the hexadecimal values of the ASCII codes of the characters in your string, since this is how they are stored in memory. 31 hex = ASCII '0', 32 hex = ASCII '1', etc.

Note that to convert an ASCII digit such as '0' to its corresponding byte value you need to subtract 0x30. Conversely you can convert a decimal digit stored as a byte to its equivalent ASCII character code by adding 0x30.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top