PDA

View Full Version : word bits?



Colin
28-03-2011, 04:33 PM
Hi there, i'm having a few problems shifting a word about. i need to have the first 4 bits equal to 3 and the following 12bits to be an offset

e.g.

4bits = 3
12bits = 2000

i'm not sure if i am doing it correctly. doesnt seem to work.

diff = a word value such as 2000



output := (Diff and $FFF) or (3 shl 12);


any help will be appreciated

JSoftware
28-03-2011, 06:10 PM
When you say "first 4 bits" do you then mean most or least significant bits?

My guess is that you mean least(sounds like you're doing some addressing), which means your code should look like:

output := ((Diff and $FFF) shl 4) or 3;

Colin
28-03-2011, 06:15 PM
hi JSoftware, it is for reloc section of dll, according to documentation



The Block Size field is then followed by any number of Type or Offset field entries. Each entry is a WORD (2 bytes) and has the following structure.

Offset Size Field Description
0 4 bits Type Stored in the high 4 bits of the WORD, a value that indicates the type of base relocation to be applied. For more information, see section 6.6.2, “Base Relocation Types.”
0 12 bits Offset Stored in the remaining 12 bits of the WORD, an offset from the starting address that was specified in the Page RVA field for the block. This offset specifies where the base relocation is to be applied.


actually the microsoft documentation lacks alot of information..

note .... the result still seems to be incorrect.

JSoftware
28-03-2011, 07:41 PM
Why do you use the offset? I just took a look in the FPC linker code, and it only sets the IMAGE_REL_* 4bit value, and it even puts it in the 4 lowest bits

Colin
28-03-2011, 08:19 PM
sorry i dont understand what you mean, can you clarify?

EDIT:
i think the value is not my problem it seems...i guess i am just writing the reloc block wrong, is there any small samples of outputting the .reloc block? thanks in advance.


RE-EDIT:
never mind i solved my problem - it was not this at all, there was missing information inside the ms documentation. thanks anyways.