Questions tagged [sign-extension]

72 questions
4
votes
1 answer

what is most efficient code to sign-extend large integers?

I am writing a code library in x86-64 assembly-language to provide all conventional bitwise, shift, logical, compare, arithmetic and math functions for s0128, s0256, s0512, s1024, s2048, and s4096 signed-integer types and f0128, f0256, f0512, f1024,…
honestann
  • 1,374
  • 12
  • 19
3
votes
2 answers

How to sum integers with sign into a wider sum on IA32. 64-bit sum of 32-bit signed ints?

I'm trying to sum a list of integers with sign on Assembly 32 but i have only got to sum integers without sign. Do you know some way to do it? My program tries to sum integers and store in resultado, whose size is 64 bits, so to be able to do that I…
Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33
3
votes
1 answer

Sign extending from a variable bit width

Here is a code in C++: #include #include using namespace std; void sign_extending(int x,unsigned b) { int r; // resulting sign-extended number int const m = CHAR_BIT * sizeof(x) - b; r = (x << m) >> m; cout <<…
Muhammad Ali Qadri
  • 606
  • 2
  • 8
  • 21
3
votes
1 answer

sign extension using concatenation

I need to make sign extension from a 4-bit number to a 32-bit number. I try to repeat the MSB 28 times like this: assign x={28'b{a[3]},a[3:0]}; But, I get an error: Syntax error near "{" x is defined as :wire [31:0] x ; a is defined as : input…
2
votes
0 answers

Assembly movsbq instruction

I understood the difference between movz and movs. movz fills the empty bytes with zeros while movs fills them with sign bit (zeros or ones). However, I came accross the following example movabsq $0x0011223344556677, %rax movb $0xAA, %dl movb %dl,…
user14596364
2
votes
1 answer

Zero/Sign extension in assembly without using MOVZX/MOVSX

I'm trying to do a zero or sign extension but without using MOVZX or MOVSX. I basically want to mimic the said commands, but not use them. Is there a way to do it? To add 0 from the left there's SHR but I'm not quite sure that it works the same…
nit17
  • 47
  • 5
2
votes
2 answers

Why does 2's complement sign extension work by adding copies of the sign bit?

Let's take the example of sign-extending a 16-bit signed number into a 32-bit register, such as mov $+/-5, %ax movswl %ax, %ebx. There are two possible cases: High bit is zero (number is positive). This is very easy to understand and intuitive. For…
2
votes
1 answer

What is the effect of the displacement value on the Mod field of the ModRegRm byte?

I'm writing an 8086 assembler that takes instructions and produce 8086 machine code. I use the "Intel 8086 User Manual" as a reference. To make it clear I will explain the situation. Let's say I wanna assemble this instruction mov ax, bx. I will…
Moe
  • 432
  • 1
  • 6
  • 21
2
votes
1 answer

is this the right way to use cbw in Mul?

I get the Multiplication from 8bit and 8bit register. But, when you have one in 16 bit, and one in 8bit, how do we do the conversion before multiplying: Question : need to provide code fragments for 260*19, and print the results. I did: mov…
Zatom
  • 19
  • 5
2
votes
1 answer

How to perform bit extension in system verilog?

I want to replicate one bit for specific times using replication opreator {} but I get only the first bit as I want and others are zeros whether the bit is zero or one. module(logic output [7:0] a); assign a={8{1}}; endmodule I get a equals…
Hussien Mostafa
  • 159
  • 2
  • 18
2
votes
2 answers

What does "extend immediate to 32 bits" mean in MIPS?

I'm reading about the Instruction Decode (ID) phase in the MIPS datapath, and I've got the following quote: "Once operands are known, read the actual data (from registers) or extend the data to 32 bits (immediates)." Can someone explain what the…
2
votes
1 answer

load byte instruction in MIPS

I am learning about Computer architecture through the MIPS instructions. I have a question which is: Memory at 0x10000000 contains 0x80 Register $5 contains 0x10000000 What is put in register $8 after lb $8,0($5) is executed? I was thinking when the…
2
votes
3 answers

Zero/sign-extend are no-op, why then instructions for each size type?

For x86 and x64 compilers generate similar zero/sign extend MOVSX and MOVZX. The expansion itself is not free, but allows processors to perform out-of-order magic speed up. But on RISC-V: Consequently, conversion between unsigned and signed 32-bit…
yudre
  • 21
  • 2
2
votes
3 answers

andi vs. addi instruction in MIPS with negative immediate constant

Assume $t2=0x55555550, then executing the following instruction: andi $t2, $t2, -1 $t2 becomes 0x0005550 This is confirmed by the MIPS emulator1 However, it is not what I expected. I think the answer should be 0x55555550 & 0xFFFFFFFF =…
2
votes
2 answers

Bit field specialization in python

Here is a code in C++: void sign_extending(int x) { int r; // resulting sign extended number goes here struct {signed int x:5 ;} s; r = s.x = x; cout << r; } void Run() { int x=29; // this 29 is -3 ( 11101 ) in 5 bits // convert this…
Muhammad Ali Qadri
  • 606
  • 2
  • 8
  • 21