86 ASM的Linux - 使用.bss节 [英] x86 ASM Linux - Using the .bss Section

查看:272
本文介绍了86 ASM的Linux - 使用.bss节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这些问题很简单:(NASM编译器,Linux和英特尔的x86语法)

第1部分:

我试图找出如何使用汇编程序的.bss段找到一种方法来存储值,比如一个值从操作(+ - * /),一个声明的变量。例如:

  .bss段变量:RESB 50;虚拟缓冲器.text段添加10,1;操作
;将结果变成变量

所以,我知道这是可能的内核intterupt要做到这一点,用于读取用户输入(但涉及字符串,但有没有办法为这个值复制到的变量的变量,以便它以后可以用吗?这将是不必打开和关闭的压栈和弹出两件事情要容易得多。

第2部分:

有没有办法去除.bss段变量的值?换句话说,如果我想保存在.bss中变量的新值,我怎么能做到这一点,而不字符/值已在没有得到复合新值(S)?

变量

感谢


解决方案

  .bss段变量:4 RESB

...符号变量现在指的是4个字节存储在的.bss 段的地址(即足以存储在一个32位的值)。

  .text段
...
MOV EAX,123
MOV [变量],EAX

...设置 EAX 注册 123 ,然后存储的值 EAX 通过符号寻址的位置变量

  MOV EAX,[变量]

...读取当前存储在由变量寻址地址的值 EAX 注册。

  MOV EAX,456
MOV [变量],EAX

...存储一个新值,覆盖previous之一。

I hope these questions is rather simple: (NASM Compiler, Linux, x86 Intel Syntax)

PART 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:

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 variable variable 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:

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)?

Thanks

解决方案

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).

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.

mov eax, [variable]

... reads the value currently stored in the location addressed by variable into the eax register.

mov eax, 456
mov [variable], eax

... stores a new value, overwriting the previous one.

这篇关于86 ASM的Linux - 使用.bss节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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