flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Macro to display registers |
Author |
|
decard 19 Aug 2004, 18:22
It would be impossible to do something like this with macros, rather with some run-time procedures. What about just simply running your program under some debugger?
|
|||
19 Aug 2004, 18:22 |
|
Imagist 19 Aug 2004, 19:38
I don't have a debugger right now, and even if I did, I wouldn't use it much. It's much easier to insert something like "display_registers" at problem spots.
_________________ Many things are possible. Few things are likely. |
|||
19 Aug 2004, 19:38 |
|
decard 19 Aug 2004, 20:06
simple solution that I wrote now (works on windows console app):
Code: format PE console entry start include "%fasminc%/win32a.inc" section '.code' code readable executable start: call display_registers finish: invoke ExitProcess,0 display_registers: cinvoke printf, szRegs, eax,ebx,ecx,edx,esi,edi,ebp,esp retn section '.data' data readable writeable szRegs db "Registers: ", 13, 10 db "eax: %x", 9, "ebx: %x", 13, 10 db "ecx: %x", 9, "edx: %x", 13, 10 db "esi: %x", 9, "edi: %x", 13, 10 db "ebp: %x", 9, "esp: %x", 13, 10, 0 section '.idata' import data readable library kernel32,"KERNEL32.DLL",\ crtdll,"CRTDLL.DLL" import crtdll,\ printf,"printf" include "%fasminc%/apia/kernel32.inc" whenever you call "display_registers" function, contents of all regs will be displayed. |
|||
19 Aug 2004, 20:06 |
|
mike.dld 19 Aug 2004, 20:35
this might be done by printing to buffer with wsprintfA (user32.dll) and then printing buffer to console, without any crtdll.dll
|
|||
19 Aug 2004, 20:35 |
|
coconut 20 Aug 2004, 00:10
how is it that this works decard, whats %x
|
|||
20 Aug 2004, 00:10 |
|
Imagist 20 Aug 2004, 04:26
Quote: It would be impossible to do something like this with macros, Well, I got the idea from a book on MASM, where they used it as a macro. They didn't give the source code for it, but if it is possible in MASM, I would assume it is also possible in FASM. But I'm interested in the way you did it. I'm not sure how the .data section works, and I don't know what cinvoke or retn do yet. Would this work with the GUI? |
|||
20 Aug 2004, 04:26 |
|
decard 20 Aug 2004, 06:56
in FASM it can be implemented with help of macros too (but it isn't actually a macro that displays the contents of registers, macro just calls specified function):
Code: format PE console entry start include "%fasminc%/win32a.inc" macro display_registers { cinvoke printf, szRegs, eax,ebx,ecx,edx,esi,edi,ebp,esp } section '.code' code readable executable start: display_registers invoke ExitProcess,0 section '.data' data readable writeable szRegs db "Registers: ", 13, 10 db "eax: %x", 9, "ebx: %x", 13, 10 db "ecx: %x", 9, "edx: %x", 13, 10 db "esi: %x", 9, "edi: %x", 13, 10 db "ebp: %x", 9, "esp: %x", 13, 10, 0 section '.idata' import data readable library kernel32,"KERNEL32.DLL",\ crtdll,"CRTDLL.DLL" import crtdll,\ printf,"printf" include "%fasminc%/apia/kernel32.inc" - data section is simply a place where you declare your data (program's varaibles etc) - printf function uses C calling convention, that's why you have to use cinvoke instead of invoke; - retn (actually the same as ret) is "return from procedure" - see some asm tutorial for details. In GUI it is also possible, although a bit more complicated: Code: format PE GUI 4.0 entry start include "%fasminc%/win32a.inc" macro display_registers { cinvoke sprintf, szBuffer, szRegs, eax,ebx,ecx,edx,esi,edi,ebp,esp invoke MessageBox, 0,szBuffer,szRegisters,MB_OK+MB_ICONINFORMATION } section '.code' code readable executable start: display_registers invoke ExitProcess,0 section '.data' data readable writeable szRegisters db "Registers", 0 szRegs db "Registers: ", 13, 10 db "eax: %x", 9, "ebx: %x", 13, 10 db "ecx: %x", 9, "edx: %x", 13, 10 db "esi: %x", 9, "edi: %x", 13, 10 db "ebp: %x", 9, "esp: %x", 13, 10, 0 szBuffer rb 0x100 section '.idata' import data readable library kernel32,"KERNEL32.DLL",\ user32,"USER32.DLL",\ crtdll,"CRTDLL.DLL" import crtdll,\ sprintf,"sprintf" include "%fasminc%/apia/kernel32.inc" include "%fasminc%/apia/user32.inc" |
|||
20 Aug 2004, 06:56 |
|
mike.dld 20 Aug 2004, 10:06
in addition, you may use %08x to fill number with leading zeroes (or %08X for upper case A..F)
|
|||
20 Aug 2004, 10:06 |
|
vid 20 Aug 2004, 19:38
cocount: read description of wsprintf in winapi
|
|||
20 Aug 2004, 19:38 |
|
halyavin 21 Aug 2004, 04:53
I think you should add pushad, pushfd and popfd, popad instruction because WIN32 API (MessageBox) can change registers.
|
|||
21 Aug 2004, 04:53 |
|
Imagist 21 Aug 2004, 06:24
Quote: - data section is simply a place where you declare your data (program's varaibles etc) No... hehe. I meant the things in the .data section, not the .data section itself. I'm a newbie but I'm not that new! |
|||
21 Aug 2004, 06:24 |
|
Imagist 21 Aug 2004, 06:25
Anyway, thanks. This was very helpful.
|
|||
21 Aug 2004, 06:25 |
|
vid 21 Aug 2004, 15:08
win32 api changes eax (result), ecx and edx, others are preserved.
but i don't know how is it with FPU/MMX/SSE registers |
|||
21 Aug 2004, 15:08 |
|
halyavin 23 Aug 2004, 16:57
But we want to preserve all registers, aren't they?
|
|||
23 Aug 2004, 16:57 |
|
Imagist 23 Aug 2004, 17:59
The registers that change during the execution can be pushed onto the stack before they get changed, then popped off afterwards.
|
|||
23 Aug 2004, 17:59 |
|
vid 23 Aug 2004, 19:52
halyavin: yes, but we only need to push those 3, others are preserved by called procedure.
Likewise, our procedure has to preserve all registers except those 3. But EBP is preserved in code of "entry" and "return", and eax is result, so you only have to care about EBX, ESI, EDI |
|||
23 Aug 2004, 19:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.