Hi.

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
Posted on 2002-11-01 02:09:08 by 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

shl ax,4
ax==1101 1110 0101 0000 ;note rol ax,4 would work too

now 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
Posted on 2002-11-01 02:42:56 by MArtial_Code
Okay. Thanks.

Kuphryn
Posted on 2002-11-01 02:59:53 by 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
Posted on 2002-11-01 11:57:08 by 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
Posted on 2002-11-01 12:38:48 by Mirno
Nice! Thanks.

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

Kuphryn
Posted on 2002-11-01 13:55:29 by 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:
Posted on 2002-11-01 19:06:12 by x86asm