Activity No 6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Activity No.

BIT MANIPULATION

Course Code: CPE005 Program: BSIT

Course Title: Computer Systems Organization with Date Performed:


Assembly Language

Section: IT31FB1 Date Submitted:

Name: Justin Julius T. Cruz Instructor:

Mr. Jonathan Taylar

1. Objective:

This activity aims to demonstrate bit manipulation in Assembly Language.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:

1.1 Manipulate bits of data

1.2 Compare the different bit manipulation instructions

1.3 Create a program using the bit manipulation instructions

3. Discussion :
Bit Manipulation

Bit manipulation allows for shifting or rotating bits in an operand. It is one of


the advantages of assembly language over high level languages. The computer
can perform arithmetic and logical shifts.

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.

SAL (Shift Arithmetic Left) is identical to SHL

SAR (Shift Arithmetic Right) performs a right arithmetic shift on the


destination operand.

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.

1. Type the following program in a Notepad.

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

here: shr bl,1

Jc is_one

Mov dl,30h

Jmp print

Is_one:

Mov dl,31h

Print:

Mov ah,2

int 21h

loop here

Exit: Mov ax, 4c00h

Int 21h

Main endp
6. DATA ANALYSIS:

Table 6.1- Output of bit.asm Table 6.2- Output of bit1.asm

Table 6.3- Output of bit2.asm Table 6.4- Output of bit4.asm

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):

You might also like