flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Need added functionality to the invoke's quoted string |
Author |
|
Tomasz Grysztar 07 Apr 2006, 17:21
Since this is assembly, isn't this better:
Code: invoke MessageBox, [hwnd], <"How are ya?! ",13,10>, "Caption", MB_OK |
|||
07 Apr 2006, 17:21 |
|
bogdanontanu 07 Apr 2006, 17:58
IMHO it IS much better.
Like this you can add whatever ASCII code you like and you do not have to remember special notations for CR or LF |
|||
07 Apr 2006, 17:58 |
|
madmatt 07 Apr 2006, 18:20
Yes, that is much better , I had no idea you could do something like that . thanks again, Tomasz .
|
|||
07 Apr 2006, 18:20 |
|
Mark Larson 08 Nov 2006, 12:50
Tomasz Grysztar wrote: Since this is assembly, isn't this better: I am having problems getting that to work with printf(). I just recently converted to fasm yesterday ( I have linux installed), so it's quite possible I am doing something boneheaded. I have the cdecl.inc I got from the distribution I downloaded ( cdecl.inc). I also tried proc32.inc I got from revolution's thread on not using ebp. ( http://board.flatassembler.net/topic.php?t=5938 ) When using the cdecl.inc I get tihs error Code: flat assembler version 1.67.14 (16384 kilobytes memory) raytrace.asm [213]: invoke printf,<"Micro: %u",10>,eax error: illegal instruction. ( I just realized from the error message that CDECL.INC doesn't have "invoke" in it). when using prot32.inc from revolution I get this one ( I am not including both) Code: flat assembler version 1.67.14 (16384 kilobytes memory) raytrace.asm [213]: invoke printf,<"Micro: %u",10>,eax /home/mark/programming/include/proc32.inc [17] invoke [3]: pushd arg error: value out of range. I am also getting a second problem with nested structures. I looked up nested structures in the manual and did a search for them on the forums. I am getting a compile error from an included include file when I do this: Code: struct point x dd ? y dd ? z dd ? d dd ? ends struc cShere a point ends flat assembler version 1.67.14 (16384 kilobytes memory) raytrace.inc [30]: a point error: unexpected characters. I checked over the code carefully and I can't seem to find a problem with the way I am doing it. thanks in advance for any help Mark _________________ BIOS programmers do it fastest! |
|||
08 Nov 2006, 12:50 |
|
Tomasz Grysztar 08 Nov 2006, 13:30
For the first problem: you need a "pushd" macro as it is defined by extended Win32 headers (like the INCLUDE/WIN32AX.INC file in fasm for Windows package) to have code-embedded strings working. Also for CDECL you should use "ccall" to call the function directly and maybe "cinvoke" if you want to call the procedure indirectly (through the variable containing address to function).
For the second one: it's because you used STRUC keyword, which the low-level preprocessor's directive that expects the structure block to begin with { character (thus the "a point" is considered "unexpected" by it). |
|||
08 Nov 2006, 13:30 |
|
vid 08 Nov 2006, 14:36
Mark: these macros are only included in Win32 distribution of FASM. There is no official linux macros, altough some of win distro can be used in linux
|
|||
08 Nov 2006, 14:36 |
|
Mark Larson 08 Nov 2006, 20:43
Thanks for the help! I've been using MASM for a really long time, and I have it down pat. So it'll take me a bit to get used to fasm.
I need to be able to do 32-bit/64-bit coding ( I have Ubuntu for both), and had originally gone with yasm. But it didn't support some features I needed such nested structures. _________________ BIOS programmers do it fastest! |
|||
08 Nov 2006, 20:43 |
|
MichaelH 08 Nov 2006, 22:53
Hi folks, this is a neat trick but can someone please explain exactly what's happening in the expanded code. I have extracted all the if/else code to reveal what will be output to file.
Code: ;invoke MessageBox, 0, <"How are ya?! ",13,10>, "Caption", 0 0000020A: 6A 00 push 0 0000020C: E8 08 00 00 00 call ..continue?0000680 00000211: 43 61 70 74 69 6F 6E 00 db 'Caption',0 ..continue?0000681: 00000219: E8 10 00 00 00 call ..continue?0000682 0000021E: 48 6F 77 20 61 72 65 20 79 61 3F 21 db 'How are ya?! ',13,10,0 20 0D 0A 00 ..continue?0000682: 0000022E: 6A 00 push 0 00000230: FF 15 3C 20 40 00 call [MessageBox] How does this - Code: 00000219: E8 10 00 00 00 call ..continue?0000682 0000021E: 48 6F 77 20 61 72 65 20 79 61 3F 21 db 'How are ya?! ',13,10,0 20 0D 0A 00 ..continue?0000682: push db 'How are ya?! ',13,10,0 onto the stack so "call [MessageBox]" has the correct stack parameters. I understand with "call ..continue?0000682", EIP is pointing to 0000021E (start of the line 'How are ya?! ',13,10,0' ) but what occurs so that this gets pushed on the stack? Hope my mumbling is clear. Also is this type of coding inefficient? Is it preferable to place strings in the data section? Thanks [edit update] Well well well, this code seems to work just fine Code: ;invoke MessageBox, 0, <"How are ya?! ",13,10>, "Caption", 0 push 0 call @f db 'Caption',0 @@: call @f db 'How are ya?! ',13,10,0 @@: push 0 call [MessageBox] But what's happening? |
|||
08 Nov 2006, 22:53 |
|
vid 08 Nov 2006, 23:52
yes, this is the trick, that you can do:
Code: push ..data: jmp ..next ..data db "string",0 ..next: with this: Code: call ..next db "string",0 ..next: but the second method is INEFFICIENT!!!! Note that FASMLIB doesn't use it too (it has idata{}, udata{} macros). Processor has cache for pairing CALL/RET, and unpairing these costs something - imprediction for every return. and yes, it is preferable to place strings in data section. or more, in read-only data section, so you catch bug with modifying these data |
|||
08 Nov 2006, 23:52 |
|
MichaelH 09 Nov 2006, 02:23
I guess I should have reread the Intel Opcodes and Mnemonics before asking such a stupid question.
Quote:
So call ..continue?0000682 - Pushes Instruction Pointer - so ESP now point to 0000021E: Code continues with execution at CS:IP (EIP) - continues at 0000022E: So the next "push 0" means esp will then point to 0000022E: and hence the string db 'How are ya?! ',13,10,0 is all set to be popped off .... I love assembler more by the day Thanks for the tricks Vid. |
|||
09 Nov 2006, 02:23 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.