Sunteți pe pagina 1din 5

BCSL 022(APRIL 2012-03-17)

Q1 Shown here is a simple two-bit binary counter circuit:

The Q output of the first flip-flop constitutes the least significant bit (LSB), while the second flip-flop's Q output constitutes the most significant bit (MSB). Based on a timing diagram analysis of this circuit, determine whether it counts in an up sequence (00, 01, 10, 11) or a down sequence (00, 11, 10, 01). Then, determine what would have to be altered to make it count in the other direction.

Q2 a) Code for Program to encrypt the given string in Assembly Language


.model small .data str1 db 'AaOLZzs' len equ $ - str1 .code mov mov LEA mov L1: ax,@data ds,ax SI,str1 cx,7 mov bl,BYTE PTR [SI] cmp bl,'Z' je encrpZ cmp bl,'z' je encrpZ1 add bl,1 mov [SI],bl INC SI Loop L1

jmp ext encrpZ: mov BYTE PTR [SI],'A' INC SI Loop L1 jmp ext encrpZ1: mov BYTE PTR [SI],'a' INC SI Loop L1 ext: mov ax,4C00h int 21h end

b) Code for Program To Convert Decimal number to Binary number in Assembly Language
prnstr macro msg mov ah, 09h lea dx, msg int 21h endm data segment buf1 db "Enter a decimal number : $" buf2 db 0ah, "Invalid Decimal Number...$" buf3 db 0ah, "Equivalent Binary number is : $" buf4 db 6 db 0 db 6 dup(0) multiplier db 0ah data ends code segment assume cs:code, ds:data start : mov ax, data mov ds, ax mov es, ax prnstr buf1 mov ah, 0ah lea dx, buf4 int 21h mov si, offset buf4 + 2 mov cl, byte ptr [si-1] mov ch, 00h subtract :

mov al, byte ptr [si] cmp al, 30h jnb cont1 prnstr buf2 jmp stop cont1 : cmp al, 3ah jb cont2 prnstr buf2 jmp stop cont2 : sub al, 30h mov byte ptr [si], al inc si loop subtract mov mov mov mov calc : mul multiplier mov bl, byte ptr [si] mov bh, 00h add ax, bx inc si loop calc mov si, offset buf4 + 2 mov bx, ax mov dx, 0000h mov ax, 8000h convert : mov cx, 0000h conv : cmp bx, ax jb cont3 sub bx, ax inc cx jmp conv cont3 : add cl, 30h mov byte ptr [si], cl inc si mov cx, 0002h div cx cmp ax, 0000h jnz convert mov byte ptr [si], '$' prnstr buf3 prnstr buf4+2 stop : mov ax, 4c00h int 21h code ends end start si, cl, ch, ax, offset buf4 + 2 byte ptr [si-1] 00h 0000h

c)
PACKED BCD

Since storage on disk and in RAM is so valuable, we would like to eliminate this wasted storage. This may be accomplished by packing the BCD numbers. In a packed BCD number, each nibble has a weighted position starting from the decimal point. Therefore, instead of requiring 4 bytes to store the BCD number 5319, we would only require 2 bytes, half the storage. The upper nibble of the upper byte of our number would store the THOUSANDS value while the lower nibble of the upper byte would store the HUNDREDS value. Likewise, the lower byte would store the TENS value in the upper nibble and the UNITS digit in the lower nibble. Therefore, our previous example would be:
Thousands - Hundreds 53 01010011 Tens - Units 19 00011001

SUBROUTINE TO PACK A 2 BYTE BCD NUMBER

Lets assume that a buffer called NUMBUF contains a two digit BCD number stored in two bytes and we wish to Pack the BCD number into a single byte. We will create a Subroutine called PACKIT to pack the BCD number. Let's develop the algorithm to Pack a BCD number.
SUBROUTINE PACKIT

On Entry: 1. Register B contain the upper byte of the BCD number. 2. Register C contains the lower byte of the BCD number. On Exit: 1. Register A contains the Packed BCD Number. To pack the number we must: 1. A <= (B) 2. Rotate A Left 4 times

3. A <= (A) + (C) That's all. We could enhance our routine by checking to see if the first number is zero. If it is, we do not need to rotate 4 times. Also, this routine assumes that the number is in BCD format. If we are unsure, we should test to see if the numbers are valid BCD numbers. It would not work if the number is in ASCII. If we entered the values from the keyboard into the buffer, we would have to strip off the ASCII which occupies the upper nibble, as well as check for a valid BCD number. This is fairly simple. ASCII values for numbers beginning at 30H and end at 39H.

S-ar putea să vă placă și