flat assembler
Message board for the users of flat assembler.
Index
> Main > What does instruction `shl 8` do? |
Author |
|
acel 02 Oct 2012, 13:41
I saw this instruction in fasm source, what's the target of this instruction? Usually this op (shl) contains 2 operand, why the target is ignored by fasm?
|
|||
02 Oct 2012, 13:41 |
|
revolution 02 Oct 2012, 14:11
Where do you see that?
|
|||
02 Oct 2012, 14:11 |
|
LocoDelAssembly 02 Oct 2012, 14:56
Yes, it is calculated by the assembler (i.e. it assembles `mov eax, 256`).
|
|||
02 Oct 2012, 14:56 |
|
revolution 02 Oct 2012, 15:07
In this case SHL is not used as an instruction, it is a numeric operator. The instruction in the above line is actually MOV.
|
|||
02 Oct 2012, 15:07 |
|
AsmGuru62 02 Oct 2012, 16:41
And here is a small macro, which creates a color in Win32 using this feature:
Code: macro SetRGB dest,R,G,B { mov dest, (B shl 16) or (G shl 8) or R } ... ; ; ECX = RGB (32, 87, 228) ; SetRGB ecx, 32, 87, 228 |
|||
02 Oct 2012, 16:41 |
|
uart777 06 Oct 2012, 21:50
How about a runtime version? Assembler can resolve constant subexpressions.
Code: macro RGB r, g, b { mov eax, r ; 00.00.00.RR shl eax, 16 ; 00.RR.00.00 mov ecx, g ; 00.00.00.GG shl ecx, 8 ; 00.00.GG.00 or eax, ecx ; 00.RR.GG.00 mov edx, b ; 00.00.00.BB or eax, edx ; 00.RR.GG.BB } |
|||
06 Oct 2012, 21:50 |
|
uart777 07 Oct 2012, 01:52
Just to elaborate. Assemblers resolve constant expressions to one immediate value. When you write - add eax, (1+2+3)*2 - assembler sees it as "add eax, 12" and FASM uses the 5 byte instruction: add eax, i32 ; 05 i32
|
|||
07 Oct 2012, 01:52 |
|
AsmGuru62 07 Oct 2012, 01:58
Come to think of it - runtime version was never needed for me.
Once the colors are set by default I use the ChooseColor function and it provides a color as 32 bit value, so there was no need to make it from RGB pieces. |
|||
07 Oct 2012, 01:58 |
|
uart777 07 Oct 2012, 13:56
AsmGuru: Depends on what you're doing. In art/image/game/graphics software, there are many situations where we need to alter pixels/colors directly and calculate RGBs at runtime using registers and/or memory operands (which your macro won't accept).
|
|||
07 Oct 2012, 13:56 |
|
AsmGuru62 07 Oct 2012, 16:11
I understand.
|
|||
07 Oct 2012, 16:11 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.