如果更改CS段寄存器,会发生什么? (您会怎么做?) [英] What would happen if the CS segment register is changed? (And how would you do so?)

查看:370
本文介绍了如果更改CS段寄存器,会发生什么? (您会怎么做?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了这篇文章: http://static.patater.com/gbaguy/day3pc.htm

它包含句子

永远不要改变CS!

DON'T EVER CHANGE CS!!

但是,如果您确实修改了CS段寄存器,将会发生什么呢?为什么这么危险?

But what exactly would happen if you did modify the CS segment register? Why is it so dangerous?

推荐答案

cs是代码段. cs:ip,这意味着csip(指令指针)一起指向下一条指令的位置.因此,对csip或两者都进行的更改都会更改从下一条指令将被提取并执行的地址.

cs is the code segment. cs:ip, which means cs together with ip (instruction pointer) points to the location of the next instruction. So any change to cs or ip or to both changes the address from where the next instruction will be fetched and executed.

通常,您使用jmp(跳远),call(长途通话),retfint3intiret更改cs.在8088和8086中,pop cs也可用(操作码0x0F). pop cs在186+中不起作用,其中操作码0x0F保留用于多字节指令. http://en.wikipedia.org/wiki/X86_instruction_listings

Usually you change cs with a jmp (long jump), call (long call), retf, int3, int or iret. In 8088 and 8086 pop cs is also available (opcode 0x0F). pop cs won't work in 186+, in which the opcode 0x0F is reserved for multibyte instructions. http://en.wikipedia.org/wiki/X86_instruction_listings

跳远或长途通话没有内在的危险.您只需要知道您在哪里跳转或呼叫,并在保护模式下就需要具有足够的权限才能执行此操作.在16位实模式(例如DOS)中,您可以跳转并调用您想要的任何地址,例如. jmp 0xF000:0xFFF0cs设置为0xF000,将ip设置为0xFFF0(BIOS代码的起始地址),从而重新引导计算机.不同的内存地址具有不同的代码,从而导致不同的结果,理论上所有可能发生(如果您跳入用于格式化硬盘的BIOS代码,具有有效的寄存器和/或堆栈值,则硬盘将被格式化) '按照要求').实际上,jmpcall到大多数地址的操作可能很快就会导致无效的操作码或某些其他异常(除以零,除以溢出等).

There is nothing inherently dangerous in long jump or long call. You just have to know where you jump or call and in protected mode you need to have sufficient priviledges to do it. In 16-bit real mode (eg. DOS) you can jump and call what ever address you wish, eg. jmp 0xF000:0xFFF0 sets cs to 0xF000 and ip to 0xFFF0, which is the start address of BIOS code, and thus reboots the computer. Different memory addresses have different code and thus cause different kinds of results, in theory everything possible can happen (if you jump into BIOS code used for formatting hard-drive, with valid register and/or stack values, then the hard drive will be formatted 'as requested'). In practice jmp's and call's to most addresses probably result in invalid opcode or some other exception (divide by zero, divide overflow, etc.) quite soon.

这篇关于如果更改CS段寄存器,会发生什么? (您会怎么做?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆