variables - asm文件之间的变量导出
问题描述
在 asm file1 中,我尝试导出一个变量并在另一个中使用它。我试图从手册和教程中找到如何做到这一点,但没有成功。
那么,如何在 asm 文件之间共享一个全局变量呢?
// File 1
// Here is saved value of a register (r10) to a variable.
.section .data
.global r10_save
r10_save_addr: .word r10_save
.section .text
ldr r13, =r10_save_addr // Load address for the global variable to some reg (r13)
str r13, [r10] // Save r13 to global variable
// File 2
// Here the intention is to use the variable (that should have r10 value stored).
.section .data
str_r10:
.asciz "r10 = 0x"
strlen_r10 = .-str_r10
.section .text
/* Here I want to use the reference of a variable
which has got its value in other file.
*/
mov r0, $1 //
ldr r1, =str_r10 // address of text string
ldr r2, =strlen_r10 // number of bytes to write
mov r7, $4 //
swi 0
解决方案
您可以使用extern
来获取变量的值global
:
// File 2
// Here the intention is to use the variable (that should have r10 value stored).
.section .data
str_r10:
.asciz "r10 = 0x"
strlen_r10 = .-str_r10
.section .text
/* Here I want to use the reference of a variable
which has got its value in other file.
*/
.extern r10_save // or EXTERN DATA(r10_save)
mov r0, $1 //
ldr r1, =str_r10 // address of text string
ldr r2, =strlen_r10 // number of bytes to write
mov r7, $4 //
swi 0
然后你也可以访问r10_save
第二个文件。
推荐阅读
- flutter - DropDownFormField 无法从 api 初始化对象列表,请任何人帮助无法解决
- pandas - 根据熊猫中的数值范围添加累积值
- c - C中的字符串缩写字符序列
- angular - Angular Take 操作员需要退订吗?
- vue.js - 如何在电子商务网站中构建礼品卡(使用 Stripe)
- python - 从文本文件文件夹 FileNotFoundError 创建数据框:[WinError 3]
- c++ - 如何获取断开套接字的连接信息?
- macos-big-sur - BigSur 鼠标控制
- angular-cli - 为什么在使用 --emitDecoratorMetadata 标志编译角度库时会收到警告?
- python - 中止失败片段的作业 yt-dlp