Hi.

I have some questions about basic shift and appending in 16-bit ASM. For example:

I cannot figure out a way to append any bits to the left or right end of a register.

Thanks,

Kuphryn

I have some questions about basic shift and appending in 16-bit ASM. For example:

```
```

// Given ax

0000 1101 1110 0101

// I would like to append "0110" to the right end of the above.

// Given a temporary variable

0000 0000 0000 0110

// I would like to append the above to the end of ax.

1101 1110 0101 0110

I cannot figure out a way to append any bits to the left or right end of a register.

Thanks,

Kuphryn

heres how to do it using your example...

ax ==0000 1101 1110 0101

var==0000 0000 0000 0110

the first thing is to shift ax four bits to the left

ax==1101 1110 0101

now if we perform an

ax==1101 1110 0101

QED

have a look at the various Boolean opcodes(AND,OR,XOR,NOT) and bitwise opcodes(SHL,SHR,ROL,ROR) you'l find many uses for them especially when it comes to code optimisation

ax ==0000 1101 1110 0101

var==0000 0000 0000 0110

the first thing is to shift ax four bits to the left

**shl ax,4**ax==1101 1110 0101

**0000**;note**rol ax,4**would work toonow if we perform an

**OR**operation between**ax**and**var**, we get the correct result...**or ax,var**ax==1101 1110 0101

**0110**QED

have a look at the various Boolean opcodes(AND,OR,XOR,NOT) and bitwise opcodes(SHL,SHR,ROL,ROR) you'l find many uses for them especially when it comes to code optimisation

Okay. Thanks.

Kuphryn

Kuphryn

A member posted at programmingheaven about an Intel 80x86 instruction that would allow you to append any bits left or right of a register without OR, AND, etc.

For example:

0011 1110 1010 1011

Given:

1000 1000 1010 1001

I want to append ONLY "010 1001."

Please post if you have a good solution.

Thanks,

Kuphryn

For example:

0011 1110 1010 1011

Given:

1000 1000 1010 1001

I want to append ONLY "010 1001."

Please post if you have a good solution.

Thanks,

Kuphryn

```
```

mov eax, original_number

mov edx, appended_number

cmp append_to_top, true

je @F

mov cl, 32

sub cl, bit_length_of_appended_number

shl edx, cl

mov cl, bit_length_of_appended_number

shld eax, edx, cl

jmp end

@@:

mov cl, bit_length_of_appended_number

shrd eax, edx, cl

end:

Mirno

Nice! Thanks.

I implemented 16-bits ASM. Does the instruction shld and shrd work in 16-bits environment?

Kuphryn

I implemented 16-bits ASM. Does the instruction shld and shrd work in 16-bits environment?

Kuphryn

Nice! Thanks.

I implemented 16-bits ASM. Does the instruction shld and shrd work in 16-bits environment?

Kuphryn

Ya probably with a operand size prefix, just give it a shot and see what happens is what I say :alright: