32 bit registers act as 8 bit ones

undo_all

I've been having the strangest problem. In x86 assembly, the 32 bit registers (eax, ebx, etc.) have been overflowing at 256, suggesting that they're actually 8 bit, for some reason. For example:

test.s:

section .data
section .text

global _start
_start:
    mov eax, 1
    mov ebx, 256
    int 80h

If I then compile this code with nasm -felf32 -g test.s && ld -m elf_i386 -s -o test test.s, and run the resulting executable, it returns 0. This same problem happens for eax, ecx, edx, etc.

Why would the 32 bit registers act like 8 bit ones, in ANY situation?

paxdiablo

It's not the register wrapping around, it's the exit system call, which only uses the lower eight bits of ebx for the return code.

From the exit man-page:

The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).

That 0377 is the octal equivalent of 0xff (binary 1111 1111), meaning that only the lower eight bits are used. The other bits in what you get back from wait() (in the parent) are used for things such as whether the child process was terminated, what signal was used if so, whether a core dump occurred, and so on.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

IA-32 assembly: Effect of 8 bit operations on 32 bit registers

From Dev

Z3Py: How should I represent some 32-bit; 16-bit and 8-bit registers?

From Dev

Real Mode 32-bit registers

From Dev

Assembly: 64 bit multiplication with 32-bit registers

From Dev

Wix: How to write to 32bit registers on 64 bit machine

From Dev

Adding two 16 bit numbers using 8 bit registers (Assembly)

From Dev

Byte conversion from 32 bit to 8 bit

From Dev

Assembly 8088: 32-bit signed Multiplication with addition and bit manipulation using 16-bit registers

From Dev

Add 32-bit floats in eax/ecx registers?

From Dev

Add 32-bit floats in eax/ecx registers?

From Dev

SSE 64 bit registers

From Dev

C Bit masking registers

From Dev

C Bit masking registers

From Dev

Assembly: division using the values in two 32-bit registers as if they were one 64-bit integer

From Dev

Recieving 32-bit registers from 64-bit nasm code

From Dev

Assembly: division using the values in two 32-bit registers as if they were one 64-bit integer

From Dev

Recieving 32-bit registers from 64-bit nasm code

From Dev

Multiplication of two 32 bit numbers using only 8 bit numbers

From Dev

NumPy convert 8-bit to 16/32-bit image

From Dev

Converting 8 bit PNG to 32- bit with alpha

From Dev

C, Creating a 32 bit pointer to a 8 bit array

From Dev

Install 32 bit ubuntu along side 64 bit windows 8

From Dev

Install 32 bit ubuntu along side 64 bit windows 8

From Dev

Working with 32 bit data types and 8 bit data type in ARM

From Dev

Convert a 8bit list to a 32 bit integer array in python

From Dev

8 bit int vs 32 bit int on a 32 bit architechture (GCC)

From Dev

C - How to check if 8 bits are in 32 bit?

From Dev

Why are there 32-bit editions of Windows 8?

From Dev

Why are processes in Windows 8 32 bit?

Related Related

  1. 1

    IA-32 assembly: Effect of 8 bit operations on 32 bit registers

  2. 2

    Z3Py: How should I represent some 32-bit; 16-bit and 8-bit registers?

  3. 3

    Real Mode 32-bit registers

  4. 4

    Assembly: 64 bit multiplication with 32-bit registers

  5. 5

    Wix: How to write to 32bit registers on 64 bit machine

  6. 6

    Adding two 16 bit numbers using 8 bit registers (Assembly)

  7. 7

    Byte conversion from 32 bit to 8 bit

  8. 8

    Assembly 8088: 32-bit signed Multiplication with addition and bit manipulation using 16-bit registers

  9. 9

    Add 32-bit floats in eax/ecx registers?

  10. 10

    Add 32-bit floats in eax/ecx registers?

  11. 11

    SSE 64 bit registers

  12. 12

    C Bit masking registers

  13. 13

    C Bit masking registers

  14. 14

    Assembly: division using the values in two 32-bit registers as if they were one 64-bit integer

  15. 15

    Recieving 32-bit registers from 64-bit nasm code

  16. 16

    Assembly: division using the values in two 32-bit registers as if they were one 64-bit integer

  17. 17

    Recieving 32-bit registers from 64-bit nasm code

  18. 18

    Multiplication of two 32 bit numbers using only 8 bit numbers

  19. 19

    NumPy convert 8-bit to 16/32-bit image

  20. 20

    Converting 8 bit PNG to 32- bit with alpha

  21. 21

    C, Creating a 32 bit pointer to a 8 bit array

  22. 22

    Install 32 bit ubuntu along side 64 bit windows 8

  23. 23

    Install 32 bit ubuntu along side 64 bit windows 8

  24. 24

    Working with 32 bit data types and 8 bit data type in ARM

  25. 25

    Convert a 8bit list to a 32 bit integer array in python

  26. 26

    8 bit int vs 32 bit int on a 32 bit architechture (GCC)

  27. 27

    C - How to check if 8 bits are in 32 bit?

  28. 28

    Why are there 32-bit editions of Windows 8?

  29. 29

    Why are processes in Windows 8 32 bit?

HotTag

Archive