Jump to content
Tuts 4 You

[MASM32] A wsprintf prototype replacement


Recommended Posts

Hello guys...

The wsprintf function is very cool, but it destroy most of registers.

The most important in this function is the conversion, and the only needed return value is the size of formatted buffer.

I have written the following prototype to include some functions of wsprintf, and the only modified value in return was eax, which contains the size of buffer.

Also included is a test program.

Currently supports:

- %s (string)

- %??d (decimal signed, up to 16 chars displayed)

- %??X (haxadecimal, up to 16 chars displayed)

- %??u (decimal, up to 16 chars displayed).

The working method is like the original wsprintf function...

Any comments / ideas / tests are welcome...

Laurent aka BIGBOSS from COPs.

A little comparative

* parameters: CTEXT("%s"), CTEXT("PARAMETERS").

- wsprintf : 257 cycles. (result: PARAMETERS).

- _cpswsprintf : 71 cycles. (result: PARAMETERS). => faster

* parameters: CTEXT("%d"), -27194193.

- wsprintf : 1365 cycles. (result: -27194193).

- _cpswsprintf : 564 cycles. (result: -27194193). => faster

* parameters: CTEXT("%u"), 123456789.

- wsprintf : 1494 cycles. (result: 123456789).

- _cpswsprintf : 641 cycles. (result: 123456789). => faster

* parameters: CTEXT("%08X"), 123456789.

- wsprintf : 1222 cycles. (result: 075BCD15).

- _cpswsprintf : 299 cycles. (result: 075BCD15). => faster


Edited by bigboss-62
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...