Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SHL and SAL in 80x86

I have learned how to work with 80x86 assembler, so in bit-wise shift operation, I faced a problem with SAL and SHL usage. I means the difference between lines of code as follow :

MOV X, 0AAH SAL X, 4  MOV X, 0AAH SHL X, 4 

When we should use SHL and when use SAL? What is the difference of them?

like image 856
Hossein Mobasher Avatar asked Dec 04 '11 05:12

Hossein Mobasher


People also ask

What is Sal in assembly?

sal (or its synonym shl ) left shifts (multiplies) a byte, word, or long value for a count specified by an immediate value and stores the product in that byte, word, or long respectively.

What is SHL in assembly language?

• The SHL (shift left) instruction performs a logical left shift on the destination operand, filling the lowest bit with 0.

What is SHL x86?

The shl or sal instruction is used to shift the bits of the operand destination to the left, by the number of bits specified in the count operand. Bits shifted beyond the destination are first shifted into the CF flag. Zeros fill vacated positions during the shift operation.

What does SAR do in assembly?

SAR (Shift Arithmetic Right) performs a right arithmetic shift on its operand. The ROL instruction shifts each bit to the left, with the highest bit copied in the Carry flag and into the lowest bit. The ROR instruction shifts each bit to the right, with the lowest bit copied in the Carry flag and into the highest bit.


1 Answers

According to this, they are the same:

The shift arithmetic left (SAL) and shift logical left (SHL) instructions perform the same operation; they shift the bits in the destination operand to the left (toward more significant bit locations). For each shift count, the most significant bit of the destination operand is shifted into the CF flag, and the least significant bit is cleared (see Figure 7-7 in the Intel®64 and IA-32 Architectures Software Developer'sManual, Volume 1).

Both were probably included just for completeness since there is a distinction for right-shifts.

like image 81
Mysticial Avatar answered Oct 19 '22 12:10

Mysticial