0% found this document useful (0 votes)
16 views6 pages

BCSL 022

Uploaded by

tanzeelarahman31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

BCSL 022

Uploaded by

tanzeelarahman31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Assembly Language Programming Lab -

BCA(II)/L-022/Assignment/2024-25

Q1: Design a two-bit counter circuit using J-K Flip-Flops

State Transition Diagram:

The goal is to design a two-bit counter with the following states: 00, 01, 10, and it should
count in the sequence: 00 → 01 → 10 → 00 → 01 → 10 → 00 → ...

The state transition diagram for the counter can be shown as:

rust
Copy code
State 00 -> State 01
State 01 -> State 10
State 10 -> State 00

J-K Flip-Flop Behavior:

A J-K flip-flop has the following state transition rules:

J K Q(next) Descriptio
n

0 0 Q No change

0 1 0 Reset

1 0 1 Set

1 1 Toggle Toggle

State Table:

Let's create the state table for the counter based on the state transitions:

Present Next State J1 K1 J2 K2


State

00 01 1 0 1 0

01 10 1 0 0 1

10 00 0 1 1 0

Here:
● J1 and K1 are the inputs to the first flip-flop (Q1),
● J2 and K2 are the inputs to the second flip-flop (Q2),
● Q1 represents the first bit of the counter, and Q2 represents the second bit.

Karnaugh Maps:

To simplify the inputs for J1, K1, J2, and K2, we use Karnaugh maps.

K-map for J1 (Q1):

Q1Q2 00 01 11 10

00 1 1 0 1

01 1 1 0 1

Simplified J1: From the K-map, J1 = 1 (always set to 1).

K-map for K1 (Q1):

Q1Q2 00 01 11 10

00 0 0 1 0

01 0 0 1 0

Simplified K1: K1 = 0 (always reset).

K-map for J2 (Q2):

Q1Q2 00 01 11 10

00 1 0 1 1

01 0 0 1 1

Simplified J2: J2 = Q1 (Set J2 to the value of Q1).

K-map for K2 (Q2):

Q1Q2 00 01 11 10

00 0 1 0 0

01 1 1 0 0

Simplified K2: K2 = Q1' (Reset K2 when Q1 is 1).

Q2: 8086 Assembly Language Programs


(a) Convert a packed 4-digit BCD number to a binary number:

Objective: Convert two consecutive bytes representing a BCD number into its binary
equivalent and store it in the DX register.

Assume the memory contains two consecutive bytes:

● Byte 1: (12)h
● Byte 2: (34)h

Assembly Program:

asm
Copy code
.model small
.stack 100h

.data
bcd_num db 12h, 34h ; Packed BCD number
binary_num dw 0 ; Variable to store the result

.code
main:
; Initialize DS
mov ax, @data
mov ds, ax

; Load the first BCD digit (12h)


mov al, [bcd_num] ; AL = 12h (BCD digit 1)
mov bl, al ; Copy to BL

; Load the second BCD digit (34h)


mov al, [bcd_num + 1] ; AL = 34h (BCD digit 2)
shl ax, 8 ; Shift left by 8 bits to make space
for next 8 bits
or ax, bx ; Combine the two BCD digits

; Store the result in DX register


mov dx, ax ; Store the binary equivalent in DX

; Program end
mov ah, 4Ch
int 21h
end main

(b) Check if the input parameter is less than 5:

Objective: A subroutine checks if the input value is less than 5 and displays a message
accordingly.

Assembly Program:

asm
Copy code
.model small
.stack 100h

.data
msg1 db "Parameter value is less than 5$", 0
msg2 db "Parameter value is >= 5$", 0

.code
main:
; Initialize DS
mov ax, @data
mov ds, ax

; Call the check procedure


mov al, 3 ; Test with value 3
call check_value

; Program end
mov ah, 4Ch
int 21h

check_value proc
cmp al, 5 ; Compare AL with 5
jl less_than_5 ; Jump if less than 5

greater_equal_5:
mov dx, offset msg2
call print_msg
ret
less_than_5:
mov dx, offset msg1
call print_msg
ret

print_msg proc
mov ah, 09h ; DOS print string function
int 21h
ret
print_msg endp

check_value endp
end main

(c) Find the factorial of a value stored in the BH register:

Objective: Find the factorial of the value in the BH register (assumed maximum value is 8).

Assembly Program:

asm
Copy code
.model small
.stack 100h

.data
result db 1 ; Variable to store factorial result

.code
main:
; Initialize DS
mov ax, @data
mov ds, ax

; Load value in BH register


mov bh, 5 ; Example value 5
mov al, bh ; Copy BH to AL (AL will be used in the
loop)

; Calculate factorial
mov cl, al ; Copy AL (value to calculate factorial)
dec cl ; CL = AL-1 (starting from AL-1)

factorial_loop:
mul cl ; AL = AL * CL
dec cl ; Decrease CL by 1
jnz factorial_loop ; Repeat until CL = 0

; Store result in memory


mov [result], al

; Program end
mov ah, 4Ch
int 21h
end main

These solutions cover both the digital design and assembly programming tasks. Each
assembly program is written to follow the requested logic and can be assembled and run on
an emulator such as DOSBox or an 8086 assembly IDE.

You might also like