flat assembler
Message board for the users of flat assembler.

Index > Main > What does instruction `shl 8` do?

Author
Thread Post new topic Reply to topic
acel



Joined: 22 Jul 2012
Posts: 8
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?
Post 02 Oct 2012, 13:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
revolution 02 Oct 2012, 14:11
Where do you see that?
Post 02 Oct 2012, 14:11
View user's profile Send private message Visit poster's website Reply with quote
acel



Joined: 22 Jul 2012
Posts: 8
acel 02 Oct 2012, 14:35
Sorry for the confusion, the full instruction is actually `mov eax, 1 shl 8`, so shr here is calculated by the assembler instead of being included in the instruction encoding?
Post 02 Oct 2012, 14:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Oct 2012, 14:56
Yes, it is calculated by the assembler (i.e. it assembles `mov eax, 256`).
Post 02 Oct 2012, 14:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20448
Location: In your JS exploiting you and your system
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.
Post 02 Oct 2012, 15:07
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1670
Location: Toronto, Canada
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
    
Post 02 Oct 2012, 16:41
View user's profile Send private message Send e-mail Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
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
}    
Post 06 Oct 2012, 21:50
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
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
Post 07 Oct 2012, 01:52
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1670
Location: Toronto, Canada
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.
Post 07 Oct 2012, 01:58
View user's profile Send private message Send e-mail Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
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).
Post 07 Oct 2012, 13:56
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1670
Location: Toronto, Canada
AsmGuru62 07 Oct 2012, 16:11
I understand.
Post 07 Oct 2012, 16:11
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.