Writing to .bss section in x86 assembly

Sibi

I'm having a .bss section in which I have a buffer of 8 bytes inside it. Now, I'm looking for a way to store the number 2 inside the buffer without issuing a system call. Is that possible ?

My attempt which doesn't work:

        .section .text

        .section .bss

        .lcomm SAMPLE_BUFFER, 8

        .globl _start

_start:

        movl $2,SAMPLE_BUFFER

        movl $1, %eax
        int $0x80

On execution:

  $ as --32 buffer.s -o buffer.o
  $ ld -m elf_i386 buffer.o -o buffer
  $ ./buffer
  fish: “./buffer” terminated by signal SIGSEGV (Address boundary error)
fuz

You need to make sure to switch back to the .text section before emitting the machine code for _start. As is, you place _start in .bss which is not executable, crashing your program.

Apart from that, your code seems correct.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Writing a C function from given x86 assembly

分類Dev

x86 Assembly Programming (GAS Syntax): What reigsters are the variables defined in the data section stored in?

分類Dev

x86 Assembly pointers

分類Dev

Assembly x86 MASM loop analysis

分類Dev

LinkedList in Assembly x86 Irvine

分類Dev

Swapping 2 integers in assembly x86

分類Dev

Change the bitmap via x86 assembly

分類Dev

Semaphore implementation using x86 assembly

分類Dev

x86 Assembly: Comparisons (GAS syntax)

分類Dev

x86 assembly: Compare DWORD variable

分類Dev

x86 ASM Linux-.bssセクションの使用

分類Dev

Assembly x86 putting values into array with loop

分類Dev

ascii char to char conversions Assembly x86?

分類Dev

x86 assembly OS hello world not working as expected

分類Dev

Manipulate string in assembly x86 (mov and print to screen)

分類Dev

_attribute(section("NC_BSS")... どういう意味?

分類Dev

Why does my data section appear twice in the compiled binary? Ubuntu, x86, nasm, gdb, reaelf

分類Dev

Can an x86 assembly interrupt service routine call another interrupt?

分類Dev

Why is the output wrong after the second call of my print function? (x86 Assembly)

分類Dev

Error Raised When Attempting to Assign Value At Index of Array With x86 Assembly GNU GAS

分類Dev

ANSI escape codes not functioning when I printf them in x86 Assembly?

分類Dev

In x86 assembly, when should I use global variables instead of local variables?

分類Dev

x86 Assembly (AT&T): How do I dynamically allocate memory to a variable at runtime?

分類Dev

the data segment is not being initialized in assembly x86 even though i did set an initial value to the variables

分類Dev

Why are the %al register and stack modified before calling printf x86 assembly from C "Hello World" program compiled by gcc

分類Dev

Swap function in x86-64 assembly

分類Dev

x86 Irvine Assembly jmp + cmpおよび条件付きループ-クラップスゲーム

分類Dev

Where are the system codes coming from in x86-64 Assembly?

分類Dev

Why parameters stored in registers and not on the stack in x86-64 Assembly?

Related 関連記事

  1. 1

    Writing a C function from given x86 assembly

  2. 2

    x86 Assembly Programming (GAS Syntax): What reigsters are the variables defined in the data section stored in?

  3. 3

    x86 Assembly pointers

  4. 4

    Assembly x86 MASM loop analysis

  5. 5

    LinkedList in Assembly x86 Irvine

  6. 6

    Swapping 2 integers in assembly x86

  7. 7

    Change the bitmap via x86 assembly

  8. 8

    Semaphore implementation using x86 assembly

  9. 9

    x86 Assembly: Comparisons (GAS syntax)

  10. 10

    x86 assembly: Compare DWORD variable

  11. 11

    x86 ASM Linux-.bssセクションの使用

  12. 12

    Assembly x86 putting values into array with loop

  13. 13

    ascii char to char conversions Assembly x86?

  14. 14

    x86 assembly OS hello world not working as expected

  15. 15

    Manipulate string in assembly x86 (mov and print to screen)

  16. 16

    _attribute(section("NC_BSS")... どういう意味?

  17. 17

    Why does my data section appear twice in the compiled binary? Ubuntu, x86, nasm, gdb, reaelf

  18. 18

    Can an x86 assembly interrupt service routine call another interrupt?

  19. 19

    Why is the output wrong after the second call of my print function? (x86 Assembly)

  20. 20

    Error Raised When Attempting to Assign Value At Index of Array With x86 Assembly GNU GAS

  21. 21

    ANSI escape codes not functioning when I printf them in x86 Assembly?

  22. 22

    In x86 assembly, when should I use global variables instead of local variables?

  23. 23

    x86 Assembly (AT&T): How do I dynamically allocate memory to a variable at runtime?

  24. 24

    the data segment is not being initialized in assembly x86 even though i did set an initial value to the variables

  25. 25

    Why are the %al register and stack modified before calling printf x86 assembly from C "Hello World" program compiled by gcc

  26. 26

    Swap function in x86-64 assembly

  27. 27

    x86 Irvine Assembly jmp + cmpおよび条件付きループ-クラップスゲーム

  28. 28

    Where are the system codes coming from in x86-64 Assembly?

  29. 29

    Why parameters stored in registers and not on the stack in x86-64 Assembly?

ホットタグ

アーカイブ