program-counter

Program Counter and Instruction Register

你说的曾经没有我的故事 提交于 2019-12-02 14:08:14
Program counter holds the address of the instruction that should be executed next, while instruction register holds the actual instruction to be executed. wouldn't one of them be enough? And what is the length of each one of these registers? Thanks. Haleeq Usman You will need both always. The program counter (PC) holds the address of the next instruction to be executed, while the instruction register (IR) holds the encoded instruction. Upon fetching the instruction, the program counter is incremented by one "address value" (to the location of the next instruction). The instruction is then

ARM Cortex M3 How do I determine the program counter value before a hard fault?

不羁的心 提交于 2019-11-30 05:27:16
I have an embedded project using a STM32F103 (ARM Cortex M3), it is getting a occasionally getting hard fault in release mode. As part of recovery, I would like to retrieve the PC value from before the hard fault and store it for later debugging in the battery backed region. How would I determine the value of the program counter at the point of the hard fault? Obviously, the PC is now set to its location within the hardfault interrupt. Where should I look? It there an address for the normal mode register bank? Thanks! Cortex-M3 uses a quite different model of exception handling from the

ARM Cortex M3 How do I determine the program counter value before a hard fault?

时间秒杀一切 提交于 2019-11-29 03:57:40
问题 I have an embedded project using a STM32F103 (ARM Cortex M3), it is getting a occasionally getting hard fault in release mode. As part of recovery, I would like to retrieve the PC value from before the hard fault and store it for later debugging in the battery backed region. How would I determine the value of the program counter at the point of the hard fault? Obviously, the PC is now set to its location within the hardfault interrupt. Where should I look? It there an address for the normal

How to modify return address on Stack in C or Assembly

点点圈 提交于 2019-11-29 02:46:25
As you know, when a subroutine calls, current PC (program counter) value stores in stack. I want to modify it inside the subroutine, like below. I want do this on Intel Core-i7 3632QM using gcc compiler. void main() { foo(); } void foo() { pop return address from stack; modify return address; push it to stack; } This is almost certainly an XY problem, you didn't say what you really want to do. Anyway, here is sample code that modifies the return address: #include <stdio.h> #include <stdlib.h> void bar() { puts("entered the bar ;)"); exit(0); } void** search(void** addr, void* value) _

How to modify return address on Stack in C or Assembly

安稳与你 提交于 2019-11-27 17:19:12
问题 As you know, when a subroutine calls, current PC (program counter) value stores in stack. I want to modify it inside the subroutine, like below. I want do this on Intel Core-i7 3632QM using gcc compiler. void main() { foo(); } void foo() { pop return address from stack; modify return address; push it to stack; } 回答1: This is almost certainly an XY problem, you didn't say what you really want to do. Anyway, here is sample code that modifies the return address: #include <stdio.h> #include

Why can't you set the instruction pointer directly?

久未见 提交于 2019-11-27 01:35:52
The Wikipedia article about x86 assembly says that "the IP register cannot be accessed by the programmer directly." Directly means with instructions like mov and add. Why not? What is the reason behind this? What are the technical restrictions? You can't access it directly because there's no legitimate use case. Having any arbitrary instruction change eip would make branch prediction very difficult, and would probably open up a whole host of security issues. You can edit eip using jmp , call or ret . You just can't directly read from or write to eip using normal operations Setting eip to a

Why can&#39;t you set the instruction pointer directly?

二次信任 提交于 2019-11-26 09:09:40
问题 The Wikipedia article about x86 assembly says that \"the IP register cannot be accessed by the programmer directly.\" Directly means with instructions like mov and add. Why not? What is the reason behind this? What are the technical restrictions? 回答1: You can't access it directly because there's no legitimate use case. Having any arbitrary instruction change eip would make branch prediction very difficult, and would probably open up a whole host of security issues. You can edit eip using jmp

Reading program counter directly

走远了吗. 提交于 2019-11-26 02:09:51
Can the program counter on Intel CPUs can be read directly (that is without 'tricks') in kernel mode or some other mode? Cody Brocious No, EIP / IP cannot be accessed directly, but in position-dependent code it's a link-time constant so you can use a nearby (or distant) symbol as an immediate. mov eax, nearby_label ; in position-dependent code nearby_label: To get EIP or IP in position-independent 32-bit code: call _here _here: pop eax ; eax now holds the PC. On CPUs newer than Pentium Pro (or PIII probably), call rel32 with rel32=0 is special-cased to not affect the return-address predictor

Reading program counter directly

做~自己de王妃 提交于 2019-11-26 01:00:57
问题 Can the program counter on Intel CPUs can be read directly (that is without \'tricks\') in kernel mode or some other mode? 回答1: No, EIP / IP cannot be accessed directly, but in position-dependent code it's a link-time constant so you can use a nearby (or distant) symbol as an immediate. mov eax, nearby_label ; in position-dependent code nearby_label: To get EIP or IP in position-independent 32-bit code: call _here _here: pop eax ; eax now holds the PC. On CPUs newer than Pentium Pro (or PIII