I've seen two replies to my fisrt TASK #1. One is overreflected The other is nobly protecting :) And no code or solutions at all. Nice start :)..... I lack discussion on asm programming topics not asm programming reference topics. Eager to learn something new :) So if you want to teach me a lesson - here I am. But please, this time don't bother to reply if you have nothing to say but discuss my personality :) I thought this msgboard for asm programmers not for "life.sys" talkers :) May be the first task was too difficult? Here is simple one: TASK #3 in .data section you have iconic db 'This window is iconic',0 noticonic db 'This window is not iconic',0 in .code ... invoke IsIconic,hWnd ; write code here which display appropriate string upon the ; func. return in MsgBox . Code MUST NOT consist any jmps or jcc Good luck with new interesting ideas! The Svin.
Please remember this is without the aid of any docs etc. Plus I know its not quite how the original was set but... And yes it is slow cos of the IMUL, and could be done with a couple of movs shls, and an or! But I'm lazy :D .data iconic db 'This window is not iconic',0,'This window is iconic',0 ... invoke IsIconic,hWnd ; write code here which display appropriate string upon the ; func. return in MsgBox . Code MUST NOT consist any jmps or jcc ;Assume IsIconic returns 1 for Iconic, else 0, in eax imul eax, 26 ;get offset into "iconic" add eax, ADDR iconic invoke MessageBox, ** What ever goes here no docs sorry! ** ;Note I reversed order of the strings, plus concatenated them! Mirno
Same goes as before, no docs etc. blah, blah! .data iconic db 'This window is not iconic',0,0,0,0,0,0,0,'This window is iconic',0 ... shl eax, 5 add eax, ADDR iconic More wasteful on the iconic, but saves clocks, like it needs it ;) Mirno
Svin, Here is MY answer to your little quiz.
Knowing your minimalist style, I can already see you squirming at my answer. Not a thing you say will dissuade me from this. ;-) My main goal in programming is CLEAR, concise code. Going to unclear things to reduce a few instructions is not a good thing, as it makes bugs too hard to see (as if they were eazy to spot anyway). First off, I'd define the strings right inside the proc and let the linker move em. This way anyone can tell what's going on. (However, being a neatness freak, they just might wind up back in a global .data area after final debug.) Using the built in .IF/ELSE/.ENDIF macros doesn't add much of a performance hit at all. In fact, it's just a single extra 2 bytes for the 'or eax, eax' the top .IF adds to insure a proper comparison. Had I just tested the flag (.IF !ZERO?) I could have droped this extra instruction, but that's slightly obtuse to my eyes. I don't begrudge myself an extra text here and there. One 'fancy-f*ck' I probably would add into one of my own apps would be:
IsIconic PROC hWnd:DWORD LOCAL wp:WINDOWPLACEMENT .data iconic db 'This window is iconic', 0 noticonic db 'This window is not iconic', 0 .code invoke GetWindowPlacement, hWnd, ADDR wp mov eax, wp.showCmd and eax, SW_SHOWMINNOACTIVE .IF eax ; we have an iconic window invoke MessageBox, hWnd, ADDR iconic, NULL, 0 .ELSE invoke MessageBox, hWnd, ADDR noticonic, NULL, 0 .ENDIF ret IsIconic ENDP
IE, I'd use conditional compilation to add the application name (*IF* defined) into the messagebox. Finally, on a personal note, I am quite impressed with your posting here, I always make a point to read from them and learn. I post my stuff at: here.is/ComInAsm Ernie This message was edited by Ernie, on 2/1/2001 12:56:18 PM
.IF eax ; we have an iconic window IFDEF sxAppName invoke MessageBox, hWnd, ADDR iconic, ADDR sxAppName, 0 ELSE invoke MessageBox, hWnd, ADDR iconic, NULL, 0 ENDIF .ELSE IFDEF sxAppName invoke MessageBox, hWnd, ADDR noticonic, ADDR sxAppName, 0 ELSE invoke MessageBox, hWnd, ADDR noticonic, NULL, 0 ENDIF invoke MessageBox, hWnd, ADDR noticonic, NULL, 0 .ENDIF
Ernie, The Svin did say without jmps! I suppose technically using .IFs you didn't use any :D And I changed the rules slightly too :) Normally I too would use a more clear method, its not as if speed is of the essence when displaying a message box! But still the challenge was there... Mirno
Hi, Mirno! Thank you, my friend, for your reply. Hi level idea is right - we can use value of eax to culculate right address of string to load (in some other cases it might be right address of handling proc) without any checking - jumping code. Art of strait procs use to be well known in the Old times of asm. Now almost complitly replaced with conditional logic algos. So you idea is to align 1st string to some number so that is eax !=0 you can shift value of address by this number. Well, it is a way (not the only way though) Align by power of two is probably the best choice. Let see if there is some other way to do the jub. (And may be you'll find better way - sure you can - just give it a try) .data iconic db 'This window is iconic',0 noticonic db 'This window is not iconic',0 noti dd offset noticonic yesi dd offset iconic .code .. invoke IsIconic,hWnd mov eax, invoke MessageBox,0,eax,0,0 ... I hope to see your solutions for other tasks too. Vale The Svin.
Yes, he did issue the challange "without jumps." My mind tends to filter such things out automatically. Umm, essentially I don't see the sense of such a limit so it dissapears. Oh well. :-)
Hi Sorry for my first abussive post ...i just vant understand why such small gems here.. Eh anyway I vote for this iconic_base db "String no.1" align 32 iconic_msg1 db "String no.2",0 .... .code shl,eax,5 add eax,offset iconic_base invoke MessageBox,.......eax ... I use this a lot in my rts game to access pre aligned matrixes in AI and paint routines that must be extra fast (mostly to get/set data) But why use such criptic code in a simple MessageBox....no speed constrains on that...are they? I say that Ernie is right...whenever you are not obligated use the slow but clear version...with .IF .ELESE .ENDIF or jumps whatever so you will know whats up after 6 months also use shl eax,5 ONLY is speed is of the essence :)
eh i forgot you can also use the conditional move instructions on Pentium's but only if you have 2 strings at maximum..
Hi, Errnie! I'm glad you've come to the discussion! TFloadS macro will load in eax apropriate addr of one of two strings depending upon unknown value of BOOLEAN used as first agrument in the macro. Whole code doesn't use any jumps so executing it will not cause any pipe flash. The execution will take 1 or 2 clocks depening on if the "value" is representing by eax (which is common case upon Win32 API func. return). If you use it in some continious loop it makes it much faster. Now, I'm asking you for favour: Modify the macro so that if "value" is represented by any of eax edx ecx ebx edi esi registers the macro would load the address of appropriate string into this register, otherwise it would load it in eax for example TFloadS edi,truestr,falsestr will load the address in edi while: .data? TFvalue dd ? .code ... TFloadS TFvalue,truestr,falsestr will load it into eax .386 .model flat,stdcall option casemap:none include C:\masm32\include\windows.inc include C:\masm32\include\user32.inc include C:\masm32\include\kernel32.inc includelib C:\masm32\lib\user32.lib includelib C:\masm32\lib\kernel32.lib TFloadS macro value,falses,trues LOCAL TTbl .data ALIGN 4 TTbl dd offset falses dd offset trues .code IFDIF
fstr db 'It is FALSE string',0
tstr db 'It is TRUE string',0
start: mov eax,TRUE
invoke IsIconic ,hWnd mov esi,esp test eax,eax sbb eax,eax and eax,MessageBox push eax push Offset MsgTitle push Offset MsgText push hWnd call dword ptr mov esp,esi ;Hows dat, and i even wrote that when i was drunk mutherfu*kers
ummm, sorry, huge bug i missed, the above !does not! work, i will patch it up, and repost, but right now, im gonna bed
may as well put in my 2c ;) .data iconic db 'This window is iconic',0 noticonic db 'This window is not iconic',0 yesno dd offset noticonic, offset iconic .code invoke IsIconic,hWnd shl eax, 2 invoke MessageBox, NULL, yesno, NULL, NULL Entro-P
invoke IsIconic,hWnd ;shl eax, 2 - You don't need it! ;invoke MessageBox, NULL, yesno, NULL, NULL invoke MessageBox,0,yesno,0,0 push yesno - 2 clocks push yeasno - 2 clocks too Don't be afraid to use coplex indexing mode - it's one of major advantages of + 386! The Svin.