Concatenate two DWORDS...

[b][red]This message was edited by crazyace at 2006-11-29 22:36:6[/red][/b][hr]
[b][red]This message was edited by crazyace at 2006-11-29 22:35:40[/red][/b][hr]
[b][red]This message was edited by crazyace at 2006-11-29 22:34:49[/red][/b][hr]
I have a project where I need to concatenate two DWORDS and remove any blank spaces between them. Each DWORD will contain only one integer number. For example, the first DWORD may contain the number 3 and the second DWORD may contain 5. I would like the output to display 35. The problem is that when I use dtoa and output the values one after another I get the following. [code]" 3 5"[/code] (10 spaces and the number.) How can I combine them for the output after all the previous calculation has been done. I am required to use the integer output macro DTOA to output all data. Any help would be greatly appreciated.

• [blue]I am not sure what is DTOA... but to convert the binary digit into ASCII symbol you need only one instruction - simply add a symbol '0' to a biray digit and you get the ASCII:
[code]
mov eax, 4 ; DWORD containing the binary 4
add eax, '0' ; Now EAX is an ASCII symbol '4'

; ^^^ Well, use AL to operate with a symbol
[/code]
[/blue]
• But how can I combine two dwords together after I do this? Thanks!

: [blue]I am not sure what is DTOA... but to convert the binary digit into ASCII symbol you need only one instruction - simply add a symbol '0' to a biray digit and you get the ASCII:
: [code]
: mov eax, 4 ; DWORD containing the binary 4
: add eax, '0' ; Now EAX is an ASCII symbol '4'
:
: ; ^^^ Well, use AL to operate with a symbol
: [/code]
: [/blue]
:

• : But how can I combine two dwords together after I do this? Thanks!
:
[blue]First, convert one DWORD and store the AL from that DWORD into a string, then compare the second one and store it beside previous one into same string. Then complete string with zero or '\$' (for DOS) and then output the whole thing into console.[/blue]
• OK, I understand some of what you are saying, but exactly how do you convert the DWORD to a string? I am also not sure what you mean by "compare" the strings? Sorry, I am a beginner. :-)

: : But how can I combine two dwords together after I do this? Thanks!
: :
: [blue]First, convert one DWORD and store the AL from that DWORD into a string, then compare the second one and store it beside previous one into same string. Then complete string with zero or '\$' (for DOS) and then output the whole thing into console.[/blue]
:

• : OK, I understand some of what you are saying, but exactly how do you convert the DWORD to a string? I am also not sure what you mean by "compare" the strings? Sorry, I am a beginner. :-)
:

[green]
Basic formula for converting from an integer to ASCII

1. set divisor to 10
2. set count to zero

3. While( quotient != zero)
4. divide quotient by 10
5. add 30h to remainder <--convert number to ASCII equivilent
6. store remainder
7. increment count by one

Number is stored in memory backwards!

example:

convert integer 1256 to ASCII results in

number db '6','5','2','1'

To print it properly:

1. set index == count

2. While ( index != zero)
3. print character at index
4. decrement index by one

That's all you have to do.
[/green]

• [blue]The 'compare' was a typo - I meant 'convert'. Here is some code:
[/blue][code]
; DATA SECTION:

strResult db '****************' ; Array of converted symbols
endOfResult dd 0 ; We need to begin storing from end of array
pstrConverted dd 0 ; This will point to converted value

; CODE SECTION:

mov eax, 6279937 ; Just a number to convert to string
; for testing purposes

; This is the procedure of converting EAX into 'pstrConverted'

mov ecx, 10 ; Divider
mov edi, endOfResult ; EDI points at the end of 'strResult'

div_10: ; Loop of dividing

xor edx, edx ; Prepare EDX:EAX for dividing
div ecx ; EDX = remainder, EAX = digit in [0..9]
add al, '0' ; Convert binary digit to ASCII digit

dec edi ; Move the pointer back
mov [edi], al ; Store that digit

test edx, edx ; see if EDX is zero?
jz .done ; nothing more to divide

mov eax, edx ; Move remainder back for more dividing
jmp div_10 ; divide again

.done:
mov pstrConverted, edi ; Now, 'pstrConverted' contains pointer
; to converted value and it is zero-terminated
[/code]