captcpsc
April 30th, 2012, 20:37
OK maybe this was too hard, or stupid or something, got several views but no help so moderator feel free to delete?
------
I'm trying to figure out what some lines of assembly language would look like in a higher level language such as C but also understand the WHY the compiler optimizer would code it like this verses something more direct.
I'm finding one of the best ways to figure this stuff out is to put the code to a test? Take values and plug them in and see what happens?
SO I try to take the extremes
EAX = 7FFFFFFF
ECX = 7FFFFFFF
3FFFFFFF00000001
3FFFFFFF S
EDX:EAX = 3FFFFFFF00000001
EDX = 3FFFFFFF / 20(32 Decimal)
SAR, 5 = 1FFFFFF
SHR EAX, 1F (so 0)
ADD EAX, EDX
EAX = 1FFFFFF
CDQ -- EDX = 00000000 EAX = 01FFFFFF
however negative makes it a bit tricky.... worst case the SHR seems to leave a 1 in EAX
SO
EAX = 80000000
ECX = 7FFFFFFF
EDX:EAX = EDX:C0000000 EAX:80000000
SAR EDX, 5 - EDX:FE000000
MOV EAX, EDX
SHR EAX, 1F EAX = 1
EAX = FE000001
CDQ creates
EDX:EAX = FFFFFFFF:FE000001
So it's not any kinda absolute function or anything? I hope someone has worked this one out before or can figure it out.
------
I'm trying to figure out what some lines of assembly language would look like in a higher level language such as C but also understand the WHY the compiler optimizer would code it like this verses something more direct.
Code:
IMUL ECX <- EDX:EAX = EAX * ECX
SAR EDX, 5 <- EDX / 32
MOV EAX, EDX
SHR EAX, 1F <--- 1F being 31 doesn't this always just clear out the register?
ADD EAX, EDX <- so basically 0 + EDX
CDQ <- wipes out EDX extends EAX so EDX:EAX?
I'm finding one of the best ways to figure this stuff out is to put the code to a test? Take values and plug them in and see what happens?
SO I try to take the extremes
EAX = 7FFFFFFF
ECX = 7FFFFFFF
3FFFFFFF00000001
3FFFFFFF S
EDX:EAX = 3FFFFFFF00000001
EDX = 3FFFFFFF / 20(32 Decimal)
SAR, 5 = 1FFFFFF
SHR EAX, 1F (so 0)
ADD EAX, EDX
EAX = 1FFFFFF
CDQ -- EDX = 00000000 EAX = 01FFFFFF
however negative makes it a bit tricky.... worst case the SHR seems to leave a 1 in EAX
SO
EAX = 80000000
ECX = 7FFFFFFF
EDX:EAX = EDX:C0000000 EAX:80000000
SAR EDX, 5 - EDX:FE000000
MOV EAX, EDX
SHR EAX, 1F EAX = 1
EAX = FE000001
CDQ creates
EDX:EAX = FFFFFFFF:FE000001
So it's not any kinda absolute function or anything? I hope someone has worked this one out before or can figure it out.