Activity No 6
Activity No 6
Activity No 6
BIT MANIPULATION
1. Objective:
3. Discussion :
Bit Manipulation
Arithmetic shift fills the newly created bit position with a copy of the number’s sign
bit. Logical Shift fills the newly created bit position with zero.
The SHL (shift left) instruction performs a logical shift on the destination
operand, filling the lowest bit with 0. When a bit is shifted to the left once, the
number is multiplied by 2. For example if we have MOV DL,6 SHL DL,1 the value
0000 0110 becomes 00001100, therefore SHL is used as fast multiplication
instruction.
SHR (Shift Right) instruction performs a logical right shift on the destination
operand. The highest bit position is filled with a zero.
ROL (Rotate) shifts each bit to the left. The highest bit is copied into both
the Carry flag and into the lowest.
ROR (Rotate Right) shifts each bit to the right, the lowest bit is copied into
both the carry flag and into the highest bit. No bits are lost in the ROR operation.
RCL (Rotate Carry Left) shifts each bit to the left. It copies the flag to the
least significant bit and the most significant bit to the carry flag.
RCR (Rotate Carry Right) shifts each bit to the right. It copies the most
significant bit to the flag and least significant bit to the flag.
4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Problem A.
TITLE bit.asm
.model small
.stack 100h
.data
num db 03Dh
.code
main proc
mov ax,@data
mov ds,ax
mov bl,num
mov cx,8
Jc is_one
Mov dl,30h
Jmp print
Is_one:
Mov dl,31h
Print:
Mov ah,2
int 21h
loop here
Int 21h
Main endp
6. DATA ANALYSIS:
PROBLEMS:
1. Modify bit.asm so that it uses 64-bit value stored at NUM. The 64-bit
number should be printed from the most significant bit to the least
significant bit.
2. Write an assembly program that will clear the most significant nibble, set
the least significant nibble and retain the values of the rest of the bits of
AX.
3. Make a program that will implement the following 10*ax = 8*ax + 2*ax
using shift or rotate instructions.
8. Assessment (Rubric for Laboratory Performance):