Questions tagged [sign-extension]

72 questions
1
vote
1 answer

Bit extension occuring when trying to store a "byte" of information into a %x

So I currently need to read in a string of hex ASCII characters and use them to determine a specific opcode. To do so I open a text file(its not really but for simple explanation we'll call it that) then read in the line. So if I get a line like…
M. Youn
  • 11
  • 1
1
vote
0 answers

gfortran sign-extension for bits manipulations

I was using the zext() function with Sun Studio Fortan compiler, to transform integer(kind=1) to integer(kind=4), in order to be able to manipulate bits with ibits() function. eg : ! Accessing the most significant bit of a byte…
1
vote
3 answers

char array to long results in unexpected value

I tried to convert a byte array to a long long readAndSkipLong(char*& b) { unsigned long ret = (b[0] << 56) | (b[1] << 48) | (b[2] << 40) | (b[3]<<32) | (b[4] << 24) | (b[5] << 16) | (b[6] << 8) | (b[7]); return ret; } My shifting seems to…
Anthea
  • 3,741
  • 5
  • 40
  • 64
0
votes
2 answers

Understanding if my code takes care of sign extension

I have a small snippet of code that I have written, I am a bit unsure if sign extension has been properly implemented here Essentially I have an array of char* data that contains values in bytes Now I wish to construct a 16 bit (2 byte) value from…
0
votes
0 answers

Convert a char to a uint in c++ in a well defined way for binary data handling

So, like the title says, I want to be able to convert between bytes loaded into memory as char* and uints. I have a program that demos some functions that seem to do this, but I am unsure if it is fully compliant with the c++ standard. Is all the…
alrav
  • 117
  • 8
0
votes
1 answer

Sign extend a register to 64-bit (set all bits = sign bit) in Thumb mode

I am using assembler for the ARM7TDMI (ARMv4T architecture). I'm using the Thumb mode because the ROM has a 16-bit bus (GBA). I want to sign-extend a 32-bit register to get another register with all bits set to a copy of bit 31 of the source…
Pedro Gimeno
  • 2,837
  • 1
  • 25
  • 33
0
votes
1 answer

Confusion about MIPS I-type instruction sign extend

I am learning the MIPS instructions, and when I test the I-type instrtuctions which need to sign extend the immediate, I am confused abou the following outcomes (All of them are run in MARS): Say we have the source code line ori $s1, $s2, 0xfd10,…
0
votes
0 answers

How to convert int8 to int16 in avr

In my computer science class, we just started working in AVR this week. I am having trouble with the bit manipulation required to convert an 8-bit int to a 16-bit int. For context, I am running the program off an arduino. This is what I have so…
0
votes
0 answers

x86 assembly - mov and movzx from dword to qword?

I'm testing the following code: .intel_syntax noprefix .data .Ltest_data: .byte 0xEF, 0xBE, 0xAD, 0xDE, 0xBE, 0xBA, 0xED, 0xFE .text ... movzx rax, BYTE PTR[.Ltest_data] # 0xEF movzx rax, WORD PTR[.Ltest_data] # 0xBEEF movsx rax,…
Martin
  • 940
  • 6
  • 26
0
votes
1 answer

_mm256_movemask_epi8 to uint64_t

Can someone please explain me why tr2 and tr4 show different result: auto test1 = _mm256_set1_epi8(-1); uint64_t tr2 = _mm256_movemask_epi8(test1); uint32_t tr3 = _mm256_movemask_epi8(test1); uint64_t tr4 =…
Marka
  • 377
  • 1
  • 4
  • 17
0
votes
1 answer

Casting signed to unsigned and vise versa while widening the byte count

uint32_t a = -1; // 11111111111111111111111111111111 int64_t b = (int64_t) a; // 0000000000000000000000000000000011111111111111111111111111111111 int32_t c = -1; // 11111111111111111111111111111111 int64_t d = (int64_t) c;…
user12950688
0
votes
1 answer

MOV 8 bit to 16 bit register (al to bx)

How can I fix the problem of moving 8 bit value to the BX register (16 bit)? mov al, 10h mov bx, al for this I get: operands do not match: 16 bit and 8 bit register
0
votes
1 answer

How to isolate byte and word array elements in a 64-bit register

I can tell this is a super simple problem but I have yet to figure it out. Basically, I just want to be able to take one element an array and add and subtract some numbers from it using registers and then put the result into my result…
Austin25
  • 3
  • 2
0
votes
1 answer

What does movsbq and this add line do?

I am trying to figure out what these lines of code do movsbq (%rbx),%rcx and add (%rdx,%rcx,4),%eax
0
votes
1 answer

why _mm_extract_epi16 doesn't get expected result?

I have found the bug in my program caused by misused SSE '_mm_extract_epi16' instruction, like below code: #include #include int main(int argc, const char * argv[]) { int16_t test_input[8] = {-1, 2, -3, -4, -5, -6, -7,…
冯剑龙
  • 569
  • 8
  • 22