Lab Manual 05
Lab Manual 05
Lab Manual 05
Course Instructor:
Lab Instructor:
Shift Operations:
Shift operations move bits to the left or right within a binary number. Shifting left multi-
plies the number by powers of 2, while shifting right divides it.
o SHL (Shift Left): Shifts bits to the left, filling with 0s on the right. It multiplies the
number by 2 for each shift.
o SHR (Shift Right): Shifts bits to the right, filling with 0s on the left. It divides the
number by 2 for each shift.
o SAL (Shift Arithmetic Left): Identical to SHL, shifts bits to the left, filling with 0s
on the right, used for signed numbers.
o SAR (Shift Arithmetic Right): Shifts bits to the right, preserving the sign bit (most
significant bit) for signed numbers.
Example:
o SHL AX, 1: Shift the bits in register AX one position to the left.
o If AX = 0010 (binary for 2), after SHL AX, 1, AX becomes 0100 (binary for 4).
For unsigned data, the logical shift fills vacated bits with 0s.
Rotate Operations:
Rotate operations move bits to the left or right, with the bit that goes off the end being moved
to the opposite side. It doesn’t lose any bits in the process.
o ROL (Rotate Left): Rotates bits to the left, with the most significant bit (MSB) mov-
ing to the least significant bit (LSB) position.
o ROR (Rotate Right): Rotates bits to the right, with the least significant bit (LSB)
moving to the most significant bit (MSB) position.
o RCL (Rotate through Carry Left): Similar to ROL, but includes the carry flag in
the rotation, shifting the carry flag into the LSB.
o RCR (Rotate through Carry Right): Similar to ROR, but includes the carry flag in
the rotation, shifting the carry flag into the MSB.
Example:
o ROL AX, 1: Rotate bits in AX to the left by 1 position, with the most significant bit
moved to the least significant position.
o If AX = 1001 (binary for 9), after ROL AX, 1, AX becomes 0011.
For signed data, rotating ensures no change in the sign of the number as the operation is
cyclic.
These operations are foundational for low-level bitwise manipulation in assembly programs.
4-Bit Multiplication Program
jmp start
multiplicand: db 13 ;4bit multiplicand (8bit space)
multiplier: db 5 ;4bit multiplier
result: db 0 ;8bit result
start:
mov cl, 4 ;initialize bit count to 4
mov bl, [multiplicand] ;load multiplicand in bl
mov dl, [multiplier] ;load multiplier in dl
checkbit:
shr dl, 1 ;move right most bit in carry
jnc skip ;skip the addition if bit is zero
skip:
shl bl, 1 ;shift multiplicand left
dec cl ;decrement bit count
jnz checkbit ;repeat if bits left
Practice Questions