logo
down
shadow

Why a Word is 2 bytes and not 4 bytes in x86 Assembly?


Why a Word is 2 bytes and not 4 bytes in x86 Assembly?

By : Jason.zhou
Date : November 22 2020, 03:03 PM
Any of those help For historical reasons. The x86 family started as a 16-bit architecture (8086). That was the time when the instruction set was defined, and all further processors have to be backward-compatible.
The 80386 was the first 32-bit processor in the x86 series.
code :


Share : facebook icon twitter icon
How to turn this simple 5 bytes back into 4 bytes ? (algorithm to convert 4 bytes into 5 bytes is known)

How to turn this simple 5 bytes back into 4 bytes ? (algorithm to convert 4 bytes into 5 bytes is known)


By : user2633784
Date : March 29 2020, 07:55 AM
Any of those help The algorithm to convert input 8 digit hex number into 10 digit are following: , From this conversion algorithm:
code :
x1 = 1 * 16^8 * 2^3
x2 = 2 * 16^7 * 2^2
x3 = 3 * 16^6 * 2^1
x4 = 4 * 16^4 * 2^4
x5 = 5 * 16^3 * 2^3
x6 = 6 * 16^2 * 2^2
x7 = 7 * 16^1 * 2^1
x8 = 8 * 16^0 * 2^0
x1 = 1 * 16^7 * 16^1 * 2^3
x2 = 2 * 16^6 * 16^1 * 2^2
x3 = 3 * 16^5 * 16^1 * 2^1
x4 = 4 * 16^4 * 2^4
x5 = 5 * 16^3 * 2^3
x6 = 6 * 16^2 * 2^2
x7 = 7 * 16^1 * 2^1
x8 = 8 * 16^0 * 2^0
x1 = 1 * 16^7 * 2^4 * 2^3
x2 = 2 * 16^6 * 2^4 * 2^2
x3 = 3 * 16^5 * 2^4 * 2^1
x4 = 4 * 16^4 * 2^4
x5 = 5 * 16^3 * 2^3
x6 = 6 * 16^2 * 2^2
x7 = 7 * 16^1 * 2^1
x8 = 8 * 16^0 * 2^0
x1 = 1 * 16^7 * 2^7
x2 = 2 * 16^6 * 2^6
x3 = 3 * 16^5 * 2^5
x4 = 4 * 16^4 * 2^4
x5 = 5 * 16^3 * 2^3
x6 = 6 * 16^2 * 2^2
x7 = 7 * 16^1 * 2^1
x8 = 8 * 16^0 * 2^0
x1 = 1 * 16^7 << 7
x2 = 2 * 16^6 << 6
x3 = 3 * 16^5 << 5
x4 = 4 * 16^4 << 4
x5 = 5 * 16^3 << 3
x6 = 6 * 16^2 << 2
x7 = 7 * 16^1 << 1
x8 = 8 * 16^0 << 0
AAAABBBB CCCCDDDD EEEEFFFF GGGGHHHH
0AAAA0BB BB0CCCC0 DDDD0EEE E0FFFF0G GGG0HHHH
void convert(unsigned char five[], unsigned char four[]) {
    four[0] = (five[0] << 1) & 0xF0  // 11110000
            | (five[0] << 2) & 0x0C  // 00001100
            | (five[1] >> 6) & 0x03; // 00000011
    four[1] = (five[1] << 3) & 0xF0  // 11110000
            | (five[2] >> 4) & 0x0F; // 00001111
    four[2] = (five[2] << 5) & 0xE0  // 11100000
            | (five[3] >> 3) & 0x10  // 00010000
            | (five[3] >> 2) & 0x0F; // 00001111
    four[3] = (five[3] << 7) & 0x80  // 10000000
            | (five[4] >> 1) & 0x70  // 01110000
            | (five[4])      & 0x0F; // 00001111
}
 08 42 10 84 21      11 11 11 11
 10 84 21 8C 63      22 22 33 33
 52 D8 D0 88 64      AB CD 12 34
 21 4E 84 98 62      45 78 96 32
 7B DE F7 BD EF      FF FF FF FF
Bit twiddling: interleave bytes in word with zero bytes using bitwise operators (<<, |, &, etc)

Bit twiddling: interleave bytes in word with zero bytes using bitwise operators (<<, |, &, etc)


By : sirproll08
Date : March 29 2020, 07:55 AM
I hope this helps you . The following is about 25% faster for me (Java 7, benchmarked using Google Caliper), YMMV may vary according to your compiler of course:
code :
long a = (input | (input << 16));
long result = (a & 0xFF000000FFL) + ((a & 0xFF000000FF00L) <<8);
First time learning assembly, is this saying a word size is 8-bytes?

First time learning assembly, is this saying a word size is 8-bytes?


By : Aayush
Date : March 29 2020, 07:55 AM
seems to work fine The terms used to describe sizes in the x86 architecture are:
byte: 8 bits word: 2 bytes dword: 4 bytes (stands for "double word") qword: 8 bytes (stands for "quad word")
x86 Assembly reading bytes from file to stack but gdb cant find bytes

x86 Assembly reading bytes from file to stack but gdb cant find bytes


By : shiv Narayan
Date : March 29 2020, 07:55 AM
hope this fix your issue Even in this short assembler program you almost hit the top most error count that's possible. The filename is not terminated with a 0 byte. You're not checking the result of the open call. You're trying to read 4 bytes while the filesize is 8. Finally you're reusing esp, hoping that it's value wasn't changed.
Solidity Assembly, the mstore function, and the width of a word in bytes

Solidity Assembly, the mstore function, and the width of a word in bytes


By : David Byrkett
Date : March 29 2020, 07:55 AM
will be helpful for those in need Solidity arrays are stored by writing out the size of the array to the first storage slot then writing out the data to the subsequent slots. So, breaking down the 2 statements:
code :
mstore(add(_output, _offst), _input)
function test() public pure returns (bytes) {
    bytes32 i = "some message";
    bytes memory o = new bytes(32); // Initializing this way sets the length to the location "o" points to. This replaces mstore(add(_output, _offst), _input).
    bytes32ToBytes(0, i, o);

    return o;
}

function bytes32ToBytes(uint _offst, bytes32 _input, bytes memory _output) internal pure {
    assembly {
        mstore(add(add(_output, _offst),32), add(_input,32))
    }
}
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org