flat assembler
Message board for the users of flat assembler.
Index
> Windows > Simulation of wsprintf |
Author |
|
roticv 17 Feb 2004, 13:26
|
|||
17 Feb 2004, 13:26 |
|
Tommy 17 Feb 2004, 15:27
Hmm...No, not until now...
|
|||
17 Feb 2004, 15:27 |
|
Tommy 17 Feb 2004, 17:45
Here's an improved version of the procedure...
Code: ; string.format (sFormat, sOutput, [args]) ; sFormat: string containing the pattern of the output string ; %s: string ; %d: decimal number ; %h: hexadecimal number in lower case ; %H: hexadecimal number in upper case ; ; %d, %h and %H also accepts ":[number of fixed digits]" ; The number in the square brackets should then be in ; [0..9] and equal one less the number of fixed digits... ; sOutput: pointer to buffer which will receive the output string ; [args]: ... ; ; Put these two variables in the data section: ; alpha_addition db 0 ; digit_count db 0 string.format: enter 0,0 mov edx,16 mov esi,[ebp+8] mov edi,[ebp+12] .loop: lodsb cmp al,"%" je .format stosb test al,al jnz .loop .done: xor eax,eax jmp .finish .error: or eax,-1 .finish: leave pop eax sub edx,8 add esp,edx jmp eax .format: lodsb cmp al,"%" jne .not_percent stosb jmp .loop .not_percent: mov [digit_count],0 push eax cmp byte [esi],":" jne .not_extra lodsb cmp byte [esi],":" je .not_extra lodsb cmp al,"0" jl .error cmp al,"9" jg .error sub al,2Fh mov [digit_count],al .not_extra: pop eax cmp al,"s" je .string cmp al,"h" je .number.lhex cmp al,"H" je .number.uhex cmp al,"d" jne .error .number.dec: mov ebx,10 call .number jmp .loop .number.lhex: mov byte [alpha_addition],27h mov ebx,16 call .number jmp .loop .number.uhex: mov byte [alpha_addition],7 mov ebx,16 call .number jmp .loop .number: mov eax,[ebp+edx] add edx,4 push edx xor ecx,ecx .number.loop: xor edx,edx div ebx push edx inc ecx test eax,eax jnz .number.loop cmp [digit_count],0 je .number.putchar push ecx mov eax,ecx movzx ecx,byte [digit_count] sub ecx,eax jz .number.prefix.end js .number.prefix.end mov al,"0" .number.prefix: stosb loop .number.prefix .number.prefix.end: pop ecx .number.putchar: pop eax add al,30h cmp al,39h jle .number.putchar.nonalpha add al,[alpha_addition] .number.putchar.nonalpha: stosb loop .number.putchar pop edx ret .string: push esi mov esi,[ebp+edx] add edx,4 .string.loop: lodsb test al,al jz .string.end stosb jmp .string.loop .string.end: pop esi jmp .loop Code: sFormat db "Hi %s! %d-lol",13,10 db "%s = offset: 0x%H:7",0 sOutput rb 100h sTemp db "everybody",0 sLabel db "start",0 stdcall string.format,sFormat,sOutput,sTemp,16,sLabel,start |
|||
17 Feb 2004, 17:45 |
|
Vortex 18 Feb 2004, 18:25
Tommy,
Nice work. Thanks. _________________ Code it... That's all... |
|||
18 Feb 2004, 18:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.