475 views

1 Answer

Best answer
1 votes
1 votes

Offset in branch instruction means the amount of displacement which has to be done in memory location from the current location of the instruction pointer. Consider an example:

100 MOV 104, C
101 MOV 103, B
102 CMP A, B
103 JNZ 106
104 MOV 103, C
105 MOV 107, D
106 MOV 109, BAX
107 MOV 110, EAX

Now as you can see JNZ (Jump Not Zero) will jump to address 106 in case the result of above instruction (CMP) is not zero. After the instruction JNZ is being fetched, and before it is executed, the Instruction Pointer (IP) is incremented to 104. The compiler (mostly) does not generate machine code with absolute addresses, since the code is liable to be relocated to any address. Instead, it would generate JNZ with an offset address. Offset is amount if displacement to be done from the address which is currently in IP when instruction is being executed. Since there is 104 in IP, so offset in JNZ would be +2 i.e will take it to 106 as desired. 

Offset in Virtual address can mean two things since it is composed of [Page Offset | Byte within a page i.e byte offset]. Memory has a page table which contains all pages. Page offset is a index in this table. A page contains several bytes. These are Byte #0, Byte #1.. etc. Byte offset is a index to one of the bytes.

So, basically offset is an displacement to be done. In case of branch instruction, offset is amount of displacement to be done in memory address, while in case of virtual address, it is amount of displacement to be done in page table (for page offset)

selected by

Related questions

0 votes
0 votes
1 answer
2
Na462 asked Nov 7, 2018
542 views
0 votes
0 votes
1 answer
4