Tuesday 7 March 2017

BCA 2nd sem /BCSL-022/Solved Assignment/Assembly Language Programming Lab/2016-2017 New

Q.1. Design a two bit counter circuit that counts from 1, that is, it will have state 01, 10, 11 only. The initial state of the counter may be assumed to be 01. The counter will be in following successive states: 01, 10, 11, 01, 10, 11, 01, 10, 11 ... Use any flip flop to design the circuit. You must design them using state transition diagram and Karnaugh's map. 


Ans



There are 2 flip-flop inputs for counter i.e. A, B. The next state of flip-flop is given in the table. DA indicates the flip flop input corresponding to flip-flop-A. This counter requires 2-flip-flops.

K-Map for DA is:


K-Map for DB is:


Thus, the simplified input equations for BCD counter are:
DA = ABC + |A|B + |A|C
DB = |B|C + BC
Down_Counter_D_Flip_Flop

The logic circuit can be made with 2 D flip flops, 2 OR gates & 4 AND gates.

Q.2.(a) Write and run an Assembly language program that converts lowercase alphabets in a given input string to uppercase. The input may consist of uppercase alphabets, special characters and lowercase alphabets. For example, for the input string A@abAYaf, the output will be A@ABAYAF. You may assume that the string is available in the memory and output is stored in a memory array.



Ans 2(a)
Each string instruction may require a source operand, a destination operand or both. For 32-bit segments, string instructions use ESI and EDI registers to point to the source and destination operands, respectively.
For 16-bit segments, however, the SI and the DI registers are used to point to the source and destination, respectively.
There are five basic instructions for processing strings. They are −
  • MOVS − This instruction moves 1 Byte, Word or Doubleword of data from memory location to another.
  • LODS − This instruction loads from memory. If the operand is of one byte, it is loaded into the AL register, if the operand is one word, it is loaded into the AX register and a doubleword is loaded into the EAX register.
  • STOS − This instruction stores data from register (AL, AX, or EAX) to memory.
  • CMPS − This instruction compares two data items in memory. Data could be of a byte size, word or doubleword.
  • SCAS − This instruction compares the contents of a register (AL, AX or EAX) with the contents of an item in memory.
Each of the above instruction has a byte, word, and doubleword version, and string instructions can be repeated by using a repetition prefix.
These instructions use the ES:DI and DS:SI pair of registers, where DI and SI registers contain valid offset addresses that refers to bytes stored in memory. SI is normally associated with DS (data segment) and DI is always associated with ES (extra segment).

DATA SEGMENTSTR DB ‘AXYBCSDEF$’
SUBSTR DB ‘BCS$’
LEN1 DB 0
LEN2 DB 0
MSG1 DB 10,13,’STRING IS : $’
MSG2 DB 10,13,’SUBSTRING IS : $’
MSG3 DB 10,13,’SUBSTRING IS FOUND AT POSITION : $’
POS DB -1
RTN DB ‘-1$’
DATA ENDS

DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX

DISPLAY MSG1
DISPLAY STR
DISPLAY MSG2
DISPLAY SUBSTR

LEA SI,STR
NXT1:
CMP [SI],’$’
JE DONE1
INC LEN1
INC SI
JMP NXT1
DONE1:
LEA DI,SUBSTR
NXT2:
CMP [DI],’$’
JE DONE2
INC LEN2
INC DI
JMP NXT2
DONE2:
DISPLAY MSG3

LEA SI,STR
MOV AL,LEN1
SUB AL,LEN2
MOV CL,AL
MOV CH,0
FIRST:
INC POS
MOV AL,[SI]
CMP AL,SUBSTR[0]
JE CMPR
INC SI
LOOP FIRST

CMPR: INC SI
MOV AL,[SI]
CMP AL,SUBSTR[1]
JNE NOTEQUAL
INC SI
MOV AL,[SI]
CMP AL,SUBSTR[2]
JE EQUAL

NOTEQUAL:
MOV POS,-1
DISPLAY RTN
JMP EXIT

EQUAL:
MOV DL,POS
ADD DL,30H
MOV AH,2
INT 21H

EXIT: MOV AH,4CH
INT 21H

CODE ENDS

END START

Q.2.(b)Write and run (using appropriate calling program) a near procedure in 8086 assembly language that converts 2 ASCII digits stored in two registers (say BH and BL) into an equivalent binary number. For example, if the BH and BL registers contain digits 4 and 5 respectively, then the binary number obtained will be 0010 1101 which is 45 in decimal. The parameters should be passed using registers and the result should be returned in AL register.


A.2.(b) 

DATA SEGMENT
BCD DB ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX,DATA
MOV DS,AX

PUSH 04H
PUSH 05H

CALL PACKBCD

MOV BCD,AL

MOV AH,4CH
INT 21H
CODE ENDS

PACKBCD PROC NEAR
POP DX

POP AX
MOV AH,AL

POP BX
MOV AL,BL

MOV CL,4
ROL AH,CL

ADD AL,AH

PUSH DX
RET
PACKBCD ENDP

END START

Q.2.(c) Write and run an 8086 assembly language program displays a string stored in memory. You must use appropriate interrupt for the same. 

A.2.(c)
DATA SEGMENT
MSG DB 10,13,’ENTER 2 DIGIT NUMBER : $’
ASC1 DB ?
ASC2 DB ?
BIN DB ?
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

LEA DX,MSG
MOV AH,9H
INT 21H

MOV AH,1
INT 21H
MOV ASC1,AL
SUB AL,30H
MOV BL,AL

MOV AH,1
INT 21H
MOV ASC2,AL
SUB AL,30H

MOV CL,04H
ROL BL,CL
OR AL,BL

MOV BIN,AL

MOV AH,4CH
INT 21H
CODE ENDS

END START

No comments:

Post a Comment