About RIP relative addressing

HPE Gen9 服务器详细安装系统教程 立即下载
 

Something that everyone wonders about is RIP relative addressing on x64 systems.  It's the default addressing mode in 64-bit programs.

RIP relative addressing basicly means that you access memory relative to the RIP register (or relative to EIP if the 32-bit address override operand is used).

All the bugs mentioned in this article regarding ml64.exe are for version 8.00.2207, I don't know about other versions. The latest version I tried is 8.00.50215.44 and that version does not contains the bugs mentioned.

When reading this article I'm assuming you already know about assembler programming, this article isn't for beginners as I'm assuming some knowledge.

NOTE: the author of diStorm64 notified me about a (rather serious) error on this page, I hereby want to thank him :)



How RIP/EIP relative addressing works in 32-bit mode

In 32-bit programs you can't do this :

But you will have to do something like this instead :


How RIP/EIP relative addressing works in 64-bit mode

In 64-bit programs you are allowed to write this :

NOTE: ML64 is stupid and doesn't allow you to write the above code sample!

It's also nice to note that the RIP is actualy pointing to the end of the instruction, so RIP will always point to the same offset regarding of how many (useless) operands you added before the opcode.


About useless operands in 64-bit mode

I hope you know what operands, opcodes etc. are :).

In 64-bit mode the segment operands are ignored and if you encode multiple REX bytes (see the AMD64/EM64T manuals) only the last REX byte is taken into account, so if you write a disassembler or if you are writing a program to emulate/protect/encrypt 64-bit executables, you need to take this behaviour into account.  The maximum size of an instruction taking all operand etc into account is 15 bytes (atleast that's what I read in the AMD64 programmer's manual).


Absolutive addressing in 64-bit mode

Absolute addressing was not supported in older ml64 versions, in the latest version I tried (8.00.50215.44) , it worked correctly! :

You had to write this to obtain the same result :

Due to a bug, older versions of ML64 did not assemble this instruction correctly :


RIP/EIP-relative addressing in ML64

I've got bad news for you, ML64, Microsoft's Macro Assembler for x64 systems, does not give us full control over RIP relative addressing.  We can't use RIP nor EIP as a parameter in an address reference.

Instead, when we access a variable then the linker will convert it to RIP relative addressing automaticly.  This means that if you write two times the same instruction that at the binary level it will not be exactly the same :

NOTE: the actualy binary output will differ from the value of RIP at link time and the location of "test" in memory at link time


RIP/EIP-relative addressing in FASM

I've got good news!  You can use RIP relative addressing with flat assembler.


RIP/EIP-relative addressing in YASM

I've got good news!  You can use RIP relative addressing with YASM.


A test program showing the old technique versus the new technique of obtaing the current value of RIP (EIP)

I wrote the following test program which will check if the next instruction is a "nop", if RIP is obtained correctly than it will point to this "nop" instruction.   I had to hardcode some instructions because my version of ML64 does not support the usage of RIP manually (!) (Zipped source code plus executable) :

In order the compile this program, you need to invoke ml64 like this :

ml64 XXX.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib

(assuming kernel32.lib and user32.lib reside in the same directory as ml64.exe)

and

(where XXX is the name of your assembly file)
 


A test program that modifies the next instruction using RIP-relative addressing

I wrote the following test program which will modify the next instruction (Zipped source code plus executable), this program needs ML64 :

In order the compile this program, you need to invoke ml64 like this :

ml64 XXX.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:Main

(assuming kernel32.lib and user32.lib reside in the same directory as ml64.exe)

and

(where XXX is the name of your assembly file)
 


Extra: Another bug in ML64

NOTE: this bug no longer exists in newer ML64 versions!

While testing the possibilites of ML64 I found another bug : ML64 allowed you to enter 16-bit addressing instructions but when you execute them, they will actually be executed as their 32-bit variants, for example :

is at the binary level exactly the same as :

 

HyperMesh 2025新功能尝鲜:用Volume Tetramesh一键生成工业级四面体网格 HyperMesh 2025推出的Volume Tetramesh功能,通过“体到体”的全新范式,实现了工业级四面体网格的一键生成。该功能利用Proximity与Curvature参数智能识别并加密几何特征,将工程师从繁琐的几何清理和表面网格划分中解放出来,在保证网格质量的同时,显著提升了前处理效率,尤其适用于发动机缸体等复杂模型的仿真分析。 阅读详情

相关推荐

UE5网络模块实战:属性复制、RPC与联机开发踩坑指南

多人联机开发中,网络同步是核心难题。UE5网络模块以服务器权威为基础,通过Actor复制、RPC和所有权机制实现多端状态一致。理解属性复制与OnRep回调、区分Server/Client/Multicast RPC的适用场景,是构建稳定联机架构的关键。本文结合数字孪生与多端协作场景,探讨如何将渲染与逻辑分离,并针对打包后网络失效、端口防火墙、崩溃排查等工程实践问题给出解决方案。通过蓝图接口解耦表现层,利用C++创建StaticMesh组件实现服务器逻辑与客户端表现分离,同时注意专用服务器不加载渲染依赖(如D

weixin_29010003的博客 274

编译器如何生成访问全局变量的代码?

全局变量如何访问

龙瑜的博客 1601

Flink on k8s 环境搭建(一)

Flink on Yarn的环境搭建过程中,需要进行配置较多,且需要搭建zookeeper Hadoop Yarn 等相关组件,安装流程比较复杂,集群出现问题重新安装的流程也比较复杂,且Yarn的3个节点中 只能起了 3个resourceManager和1个NodeManager,Flink 作业申请资源时只能 向NodeManager的节点申请资源,整体有资源瓶颈的隐患(后继flink作业会越来越多),现在尝试进行Flink on k8s 的环境搭建。

wangqiaowq的博客 3415

64位下的相对指令地址

寻找64位系统某符号特征码时发现他的MOV指令用的是相对地址,之前32位下从来没听说MOV还能用相对地址,故查阅了下Intel指令手册。 在MOV指令介绍下找到如下介绍: In 64-bit mode, the instruction’s default operation size is 32 bits. Use of the REX.R prefix permits access to a

yeshahayes的博客 2762

Vercel静态站被墙别慌!手把手教你用Cloudflare免费CDN+域名解析搞定DNS污染

本文详细介绍了如何利用Cloudflare免费CDN和域名解析解决Vercel静态网站遭遇DNS污染的问题。通过诊断DNS污染、设计Cloudflare解决方案架构、实战配置步骤以及高级调优技巧,帮助用户快速恢复站点访问并提升防护能力。

weixin_27442001的博客 712

【开源】STM32+ESP8266+MQTT多传感器数据上云OneNET(易拓展,带操作系统FreeRTOS)

【开源】STM32+ESP8266+MQTT多传感器数据上云OneNET(易拓展) 文章目录【开源】STM32+ESP8266+MQTT多传感器数据上云OneNET(易拓展)1. 相关连接1.1 本项目相关连接1.2 无操作系统简易版(旧版,有OneNET云平台设备创建和应用配置,本文不再赘述):2. 具体功能3. 硬件环境4. 云平台环境配置5. 接线6. 功能展示6.1 数据流6.2 APP应用管理6.3 串口数据7. 源码详解7.1 源码文件解析7.2 服务器与wifi配置相关7.3 源码框架7.4

ssssadw的博客 2万+

从机器码理解RIP 相对寻址

本作品采用知识共享署名 4.0 国际许可协议进行许可。转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/rip-relative-addressing 本博客同步在 http://www.cnblogs.com/papertree/p/6298763.html 1. 情景 在调试linux-3.0.0内核源码过程中,碰到一处lea指令,略有疑问。 代码如下(路...

weixin_30335575的博客 1594

手把手教你学Simulink——基于Simulink的变换器老化预测与数字孪生(Digital Twin)

这不仅是技术的演进,更是从“事后救火”到“事前预言”的降维打击。:通过本文的实战演练,你不仅掌握了功率变换器“电气-热-老化”多物理场耦合的建模哲学,更深刻领悟了如何将高深的随机过程(粒子滤波)降维成可落地、可量产的工程工具;:起初,由于数据量少,粒子滤波器预测的剩余寿命(RUL)置信区间(95%)非常宽泛(如 1000~2000小时)。在工业4.0与智能制造的浪潮下,功率变换器(如光伏逆变器、车载OBC、服务器电源)不再是孤立的硬件,而是具备“自我感知”与“寿命预知”的智能节点。

MHD0815的博客 309

解决:RIP Address Out Of Range 报错

在重启 windows Server 2008 R2 时,服务器 HP Proliant DL388 Gen 9 服务器上看到此错误。该错误可能会显示几条对您来说意义不大的消息,例如: X64 异常类型 0D - 一般保护异常 RIP 地址超出范围 RIP Address Out Of Range 您最有可能看到此错误的时间是在引导到 Server 2008 R2 安装光盘时。 要解决此错误,请在 bios 中禁用以下设置: UEFI 优化启动 ...

我有零花钱的博客 4078

2 君正底层API接口的封装1

君正的IPC芯片主要有T31、T40、T41等型号,每个型号的API接口大部分是相同的,但也存在一些不一致和差异化的地方。为了屏蔽不同芯片型号之间的差异,我们需要基于一个公共基类进行封装。在封装之前,我们需要定义自己的错误码和数据结构,用于屏蔽不同君正芯片的实现细节。为了确保整个IPC库使用统一的错误码,我们在HP_MPPErrorCode.h文件中专门定义了以下错误码。错误码囊括了参数错误、内存错误、溢出错误、不支持、密码错误、非法数据等各种异常情况。

hope_wisdom的技术博客 1596

ZYNQ PL通过EMIO ETHE1外接PHY由GMII转RGMII

1,设置EMIO方式引出ETHE1 2,从GMII过度到RGMII GMII: 发送 gmii_tx_clk gmii_tx_d[7:0] gmii_tx_en gmii_tx_er 接收 gmii_rx_clk gmii_rx_d[7:0] gmii_rx_dv gmii_rx_er RGMII: 发送 tx_clk tx_d[3:0] tx_ctrl 接收 rx_clk rx_d[3:0] rx_ctrl 首先数据总线从时钟单边沿采样8bit转变为了双边沿采样4bit,从88E1

wangjie36的博客 1万+

HP Proliant Gen9服务器重装系统出现RIP addressout of range报错

HP Proliant DL80 Gen 9服务器在安装Server 2008 R2系统时,出现RIP addressout of range报错

weixin_42123602的博客 1824

Xilinx DDR3 MIG IP核设计--汇总导航

快速上手Xilinx DDR3 IP核----汇总篇

孤独的单刀 2万+

SVN包含非法文件系统格式选项/包含非法文件系统格式选项

一、Error: “I:\svnServerPath\db\format”包含非法文件系统格式选项"addressing logical" 使用的subversion(比如1.6)和TortoiseSVN(比如1.9.7)版本不配套 解决方法:升级subversion 二、Error: 无法连接主机“127.0.0.1”: 由于目标计算机积极拒绝,无法连接。 解决方法:卸载subv

a1257427517的专栏 4447

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

006-汇编语言中的寻址模式

寻址模式是指令用来确定操作数位置的机制。它告诉处理器如何计算操作数的有效地址,从而找到指令需要的数据。不同的寻址模式提供了不同的方式来指定数据位置,使程序员能够灵活高效地访问寄存器、内存和立即数。

小宝哥Code的专栏 1930

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

X64指令基本格式

X64指令与X86指令兼容,因此不再对X86指令结构重复描述,主要以讲解X64上新特性为主。

百里杨的博客 2730

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Position Independent Code (PIC) in shared libraries on x64

E原文地址:http://eli.thegreenplace.net/2011/11/11/position-independent-code-pic-in-shared-libraries-on-x64/ The previous article explained how position independent code (PIC) works, with code compiled

一见 1054

amd64下的寻址模式

amd64下的寻址模式比32位下的寻址模式多了一种,叫RIP-Relative模式 【base】 基址 【disp32】 偏移量 【base+index】 基址+变址 【base+disp8/32】 基址+偏移量 【base+index*scale+disp8/32】 基址+变址+偏移量 amd64特有 【rip+disp32】 rip+32位偏移量,这种寻址模式好处是不依赖

lokeli的博客 612

svn:期望文件系统格式在“1”到“4”之间;发现格式“6” 的问题解决方案

这种情况出现的原因暂时不明,有人说是在未开启svn服务的时候就建库,但是我是开启的状态下建库的。 有一种建库方法可以避免这种问题,允许仓库通过file或者svn方式提交。 就是直接在svn服务器端软件的bin目录下用svnadmin create指令。

Limitless1113的专栏 4538

SVN 错误中文对照

# # Simplified Chinese translation for subversion package # This file is distributed under the same license as the subversion package. # # Update to new pot: #    msgmerge --update zh_CN.po subve

longtingjing的专栏 8224

理解Avalon总线的静态地址对齐与动态地址对齐

尽管看了不少资料,但是一直对 Avalon slave 的动态地址对齐和静态地址对齐的理解不是很透彻。前两天自己做了一个SOPC的自定义组件,通过Deprecated这个选项的不同选取,一下子就理解了Avalon slave的两种地址对齐方式之间的区别。 下面以Altera提供的PWM自定义外设的例子,介绍两种地址对齐方式的区别。该例子有所改动,源代码中的32-bit的接口被改成了8-bit

wevsa的专栏 2061

微软将在 2027 年关停 To Do,个人用户需要另寻替代待办应用

微软宣布将于2027年6月30日停用To Do应用,取代方案为Microsoft Planner。尽管曾为用户从Wunderlist迁移提供便利,此次迁移却缺乏无缝支持,尤其对个人用户影响显著。Planner在离线功能、共享列表、文件附件及打印邮件等方面存在局限,且无原生桌面客户端。数据导出路径尚不明确,用户需提前规划替代方案。

jianlu365的博客 300
上一篇: Linux HAL (Hardware Abstraction Layer)的工作原理
下一篇: obj2asm
iiprogram
博客等级 码龄25年 1068粉丝 1515原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址