
{"id":18581,"date":"2010-07-10T18:19:32","date_gmt":"2010-07-10T12:49:32","guid":{"rendered":"http:\/\/www.jeffrin.in\/?p=1974"},"modified":"2010-07-10T18:19:32","modified_gmt":"2010-07-10T12:49:32","slug":"1974-2","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2010\/07\/10\/1974-2\/","title":{"rendered":"eip in 32-bit mode and rip in 64-bit mode"},"content":{"rendered":"<p>\n<u>ABOUT Processor Register<\/u><\/p>\n<pre>\nIn computer architecture, a processor register is a quickly accessible location available to a computer's central processing unit (CPU). Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only. Registers are typically addressed by mechanisms other than main memory, but may in some cases be assigned a memory address e.g. DEC PDP-10, ICT 1900.\n<\/pre>\n<p>[bash light=&#8221;true&#8221;]<br \/>\n(gdb) info registers<br \/>\nrax            0xfffffffffffffdfc\t-516<br \/>\nrbx            0x5dc\t1500<br \/>\nrcx            0xffffffffffffffff\t-1<br \/>\nrdx            0x5dc\t1500<br \/>\nrsi            0x1\t1<br \/>\nrdi            0x7fff09cf5780\t140733357971328<br \/>\nrbp            0x2051160\t0x2051160<br \/>\nrsp            0x7fff09cf5730\t0x7fff09cf5730<br \/>\nr8             0x0\t0<br \/>\nr9             0xffffffff\t4294967295<br \/>\nr10            0x8\t8<br \/>\nr11            0x246\t582<br \/>\nr12            0x7fff09cf5780\t140733357971328<br \/>\nr13            0x7fff09cf5790\t140733357971344<br \/>\nr14            0x0\t0<br \/>\nr15            0x1\t1<br \/>\nrip            0x7f2e947000c8\t0x7f2e947000c8<br \/>\neflags         0x246\t[ PF ZF IF ]<br \/>\ncs             0x33\t51<br \/>\nss             0x2b\t43<br \/>\nds             0x0\t0<br \/>\nes             0x0\t0<br \/>\nfs             0x0\t0<br \/>\ngs             0x0\t0<br \/>\n(gdb)<br \/>\n[\/bash]<\/p>\n<pre>\nThe RIP register is the instruction pointer register. In 64\n-bit mode, the RIP register is extended to 64 bits to support\n64-bit offsets. In 32-bit x86 architecture, the instruction\npointer register is the EIP register.source:\n\n<\/pre>\n<p><u>Related STUFF<\/u><br \/>\n[text]<br \/>\nCode:<br \/>\nexample code 1 RIP-relative addressing<\/p>\n<p>.section .data<br \/>\n\tmydata: .long 0<\/p>\n<p>.section .bss<\/p>\n<p>.section .text<br \/>\n\t.global _start<br \/>\n_start:<br \/>\n\t\t\tmovq\t$64, mydata(%rdi)<br \/>\nCode:<br \/>\nexample code 2<br \/>\n.section .data<br \/>\n\tmydata: .long 0<\/p>\n<p>.section .bss<\/p>\n<p>.section .text<br \/>\n\t.global _start<br \/>\n_start:<br \/>\n\t\t\tmovq\t$64, mydata<br \/>\nand the results<\/p>\n<p>Code:<br \/>\nexample 1 RIP-relative addressing<br \/>\ncode1:     file format elf64-x86-64<\/p>\n<p>Disassembly of section .text:<\/p>\n<p>00000000004000b0 :<br \/>\n  4000b0:\t48 c7 87 bc 00 60 00 \tmovq   $0x40,0x6000bc(%rdi)<br \/>\n  4000b7:\t40 00 00 00<br \/>\nCode:<br \/>\nexample 2<br \/>\ncode2:     file format elf64-x86-64<\/p>\n<p>Disassembly of section .text:<\/p>\n<p>00000000004000b0 :<br \/>\n  4000b0:\t48 c7 04 25 bc 00 60 \tmovq   $0x40,0x6000bc<br \/>\n  4000b7:\t00 40 00 00 00<br \/>\nare we talking about a one byte reduction in code size every time I use RIP relative addressing?<br \/>\n[\/text]<br \/>\n<u>Typical RIP and EIP Knowledge<\/u><br \/>\n[text]<br \/>\nHow RIP\/EIP relative addressing works in 32-bit mode<\/p>\n<p>In 32-bit programs you can&#8217;t do this :<\/p>\n<p>mov al, [eip]<\/p>\n<p>But you will have to do something like this instead :<br \/>\ncall $ + 5<br \/>\npop ebx<br \/>\nadd ebx, 1 + 1 + 1 + 1 ; POP + ADD + ModRM + imm8<br \/>\nmov al, [ebx] ; EBX is now pointing to this instruction!<\/p>\n<p>How RIP\/EIP relative addressing works in 64-bit mode<\/p>\n<p>In 64-bit programs you are allowed to write this :<br \/>\nmov al, [rip]<br \/>\n[\/text]<br \/>\nLINK<br \/>\n<a href=\"http:\/\/developers.sun.com\/solaris\/articles\/x64_dbx.html\">http:\/\/developers.sun.com\/solaris\/articles\/x64_dbx.html<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Processor_register\">https:\/\/en.wikipedia.org\/wiki\/Processor_register<\/a><br \/>\n<a href=\"http:\/\/www.codegurus.be\/codegurus\/Programming\/riprelativeaddressing_en.htm\">http:\/\/www.codegurus.be\/codegurus\/Programming\/riprelativeaddressing_en.htm<\/a><br \/>\n<a href=\"http:\/\/www.linuxforums.org\/forum\/linux-programming-scripting\/131795-amd-64-bit-rip-relative-addressing.html\">http:\/\/www.linuxforums.org\/forum\/linux-programming-scripting\/131795-amd-64-bit-rip-relative-addressing.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ABOUT Processor Register In computer architecture, a processor register is a quickly accessible location available to a computer&#8217;s central processing unit (CPU). Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only. Registers are typically addressed by mechanisms other than main memory, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2010\/07\/10\/1974-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;eip in 32-bit mode and rip in 64-bit mode&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[950,1359,1432],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/18581"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=18581"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/18581\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=18581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=18581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=18581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}