hello! i need to make this program that lets the user input like for example 99 then the program will output 'c'.

i don't know how to start. but i thought about getting the first 9 first, then subtract 30h, the multiply it by 10. afterwards, add the other 9, then subtract 26, because c -> 99 -> is 63h in hexadecimal. but... when i try the others i need to subtract different values to convert them to hexadecimal. am i using the wrong approach?
thank you very much for your replies. :D

hello! i need to make this program that lets the user input like for example 99 then the program will output 'c'.

i don't know how to start. but i thought about getting the first 9 first, then subtract 30h, the multiply it by 10. afterwards, add the other 9, then subtract 26, because c -> 99 -> is 63h in hexadecimal. but... when i try the others i need to subtract different values to convert them to hexadecimal. am i using the wrong approach?
thank you very much for your replies. :D

Your approach starts well but then the idea of subtracting 26 (what base?) leads to wrong solution. Assuming that you want input two-digit integer values, for examples decimal 07, 99, max. 127, by int21h and ah function code 01h, ascii-result (30h..39h) in al twice done, then:

A. Processing first digit

1. AND al, 0FH ; mask 3XH to 0XH, where X is from {0,1..9}

2. XOR ah, ah ; we need AX for multiplying X by 10D

3. MOV bx, 10D ; to compute <ax> * 10 = X0D

4. MUL bx ; computes ax * bx, result in dx:ax, you only need ax

5. MOV bx, ax ; save X0D for further processing

B. Processing second digit and add both decimal digits

Because of 80x86's weak mul capability we need to restore ah first

Now get second digit and mask it, as is first digit, result is in al

7. ADD al, bl ; computes X0D + Z, where X, Z is from {0,1,..9}

The integer value of the two-digit input ascii string is in reg. al. This is the ascii number (ordinal number) of an ascii character as per your problem. Therefore you can output it without any converting by int 21h and ah code 02h. Don't forget to move al to dl prior to call 21h.

-- tesu

what does XOR ah,ah mean? I'm sorry, i'm still in basic assembly programming language and we haven't reached XORs and ANDs yet.

xor ah, ah is equivalent to mov ah, 0 ; yet a bit faster (the fasted 0 one can generate)

AND al, 0FH can be replaced by SUB al, 30H ; 3xH - 30H = 0XH (x from 0..9)

Again, logical instruction AND is faster than numeric SUB.

-- tesu

can't I just use bl and al instead of using ax and bx?

unfortunately not, for multiplication or division 16 bits registers dx:ax are required at least.

-- tesu

Made this for you quick... Is this what you wanted?
Compile it, then pass the integer to it as an argument.
Example: TEST 31
Test being the name of the file, 31 being the argument. The program will display "1" as 31 is "1"'s value

[org 0100h]

[section .text]
	mov si,0x80		;Get command argument length
	mov si,0x82		;Get arguments
	lodsb			;Advance one position in SI, place the result in AL
	shl al,4	;Shift binary value left 4 times
			;Example:: 00001111 becomes 11110000
	mov [store1],al		;Store this value for later
	lodsb			;Advance once more into SI
	shl al,4		;Shift binary value left to delete the high nybble
	shr al,4		;The old low nybble became the high nybble, this will place it back into the lower side.
	mov [store2],al		;Store it for later
	xor al,al		;Nul out AL
	mov al,[store1]		;Place the first value into AL (Remember, its a high nybble 11110000)
	add al,[store2]		;Add the second value. (Becomes 1111 1111, as an example)
	mov [result+0],al	;Place new value into a byte
	mov byte[result+1], '$'	;Place a string terminator into the byte array so it can be displayed

	mov dx,result		;Place the byte array into DX
	mov ah,9		;Function 9x21 - Display string
	int 21h			;Interrupt 21h

	mov ah,4ch		;Function 4chx21 - Exit with errorlevel
	mov al,0		;Errorlevel of 0
	int 21h			;Interrupt 21h



[section .data]
	store1 db 0
	store2 db 0
	result times 2 db 0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.