Hello,

im using inline asm in vc++ im having a problem ;/
my program does gets user input and produces a char
suppose he enters "hi"

it gets h do some changes and it becomes 33 then it move 33 to unsigned long first=0;

it gets i do some changes and it becomes 44 then it MOVE and OVERWRITE unsigned long first=0;

is there a way i could do that without overwriting so i could do at the end

wsprintf(show,"%d",first);
and first would be 3344, not only 44 as it is now.

i've been trying lots of things and nothing when it didnt worked it crashed :-[

Mark
Posted on 2001-12-08 19:54:33 by Mark-
Solution 1: use two dwords, and "%d%d" format string.
Solution 2: shift or multiple "first" and ADD your second number to it instead of MOVing.
Posted on 2001-12-08 20:08:40 by f0dder
Hello f0dder,

first solution isnt good coz i dont know how many chars hes gonna enter.

the second could be but i dont understand what u mean with shift :/ can u give me an example ?

thanks
Mark-
Posted on 2001-12-09 01:54:07 by Mark-
There are some problems with the method you're proposing, firstly you're only using a 32 bit integer to store your value, that'll limit the number of characters you can "fit" in it, its a finite amount of space!
As the buffer you wsprintf to is also a finite length, that gives you your maximum size.

By shifting, f0dder means bit shifting. In C the >> symbol means shift right, and << means shift left.
So:
1 << 2 == 4
0001b shifted left 2 places (padding with 0s) == 0100b == 4;

3 << 2 == 4;
0011b shifted left 2 == 1100b == 6;

This obviously only works with values that fill a whole value of bits (ie is a power of 2 in size). As you are working in decimal, you'll need to multiply the value by 100 (as your variables range from 0->99).

You could fill your buffer like this:
``````
// show is defined above somewhere
int i = 0;
long first;

while (true) {
first = getchar();
if (first == TERMINATE_CHAR)
break;
wsprintf(show + i, "%d", first);
while (show[i] != 0) i++;

// or: (if you don't mind "02" instead of "2" in your buffer)
// wsprintf(show + i, "%.2d", first);
// i += 2;
}
``````

This will add the characters to the buffer as they are entered, and so are only limited by the size of the buffer. This may be an easier way to do things than to store all the variables up, then write them to the buffer.

Ideally you should add some error checking with reguards to the size of the buffer too, but that is something you can do!

Mirno
Posted on 2001-12-09 07:44:51 by Mirno