x86 ASM Linux - 使用 .bss 部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8145243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
x86 ASM Linux - Using the .bss Section
提问by nmagerko
I hope these questions is rather simple: (NASM Compiler, Linux, x86 Intel Syntax)
我希望这些问题相当简单:(NASM Compiler、Linux、x86 Intel Syntax)
PART 1:
第1部分:
I am trying to figure out how to use the .bss section of an Assembly program to find a way to store values, like a value from an operation (+ - * /), to an declared variable. For example:
我想弄清楚如何使用汇编程序的 .bss 部分来找到一种方法来存储值,例如来自操作 (+ - * /) 的值到声明的变量。例如:
section .bss
variable: resb 50 ;Imaginary buffer
section .text
add 10,1 ;Operation
;move the result into variable
So, I know it is possible to do this with the kernel intterupt for reading user input (but that involves strings, but is there a way to copy this value into the variablevariable so that it can be used later? This would be much easier than having to push and pop two things on and off the stack.
所以,我知道可以使用内核中断来读取用户输入(但这涉及字符串,但有没有办法将此值复制到变量变量中以便以后使用?这会容易得多)而不是必须在堆栈上进出两个东西。
PART 2:
第2部分:
Is there a way to remove the value of the variable in the .bss section? In other words, if I want to store a new value in the .bss variable, how could I do it without the characters/values already in the variable not getting compounded with the new value(s)?
有没有办法删除 .bss 部分中变量的值?换句话说,如果我想在 .bss 变量中存储一个新值,如果变量中已有的字符/值没有与新值混合,我该怎么做?
Thanks
谢谢
采纳答案by Matthew Slattery
section .bss
variable: resb 4
... the symbol variable
now refers to the address of 4 bytes of storage in the .bss
section (i.e. enough to store a 32-bit value in).
...该符号variable
现在指的是该.bss
部分中 4 个字节的存储地址(即足以存储 32 位值)。
section .text
...
mov eax, 123
mov [variable], eax
... sets the eax
register to 123
, and then stores the value of eax
in the location addressed by the symbol variable
.
... 将eax
寄存器设置为123
,然后将 的值存储eax
在符号寻址的位置variable
。
mov eax, [variable]
... reads the value currently stored in the location addressed by variable
into the eax
register.
... 将当前存储在地址variable
为 的位置中的值读取到eax
寄存器中。
mov eax, 456
mov [variable], eax
... stores a new value, overwriting the previous one.
... 存储一个新值,覆盖前一个值。