Reputation: 471
How can you forcibly change CS
and IP
both in assembly language ?
ORG
directive can be used to change the number of the IP
, but how do you change the CS
?
Basically I wan to implement multi-threading using assembly.
Many forums, including a question in stack overflow has said its impossible, but then how does C have multi-threading options even when it is made from assembly code ?
Upvotes: 2
Views: 6624
Reputation: 1180
To change both cs
and ip
registers, use the following in AT&T syntax:
ljmp $segment, $offset
Or the following in Intel syntax:
jmp segment:offset
Upvotes: 1
Reputation:
Only far control transfer instructions (jmp, call, ret) can change the CS or EIP registers. I think the CS register can only be changed in real mode.
RET basically takes the value at ESP (stack pointer) and pushes that onto IP/EIP. Then the ESP is incremented by 8 plus the immediate offset (if exists).
Upvotes: 1
Reputation: 10570
To change cs:ip
just make a long jump with jmp
(eg. jmp segment:offset
) or a long call
(eg. call segment:offset
) depending on your needs. There are several different addressing modes available for jmp
link and call
link. Implementing multithreading is a totally different matter from simply changing cs:ip
.
Upvotes: 7