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

CAP212 : COMPUTER PERIPHERALS AND INTERFACES

HOME WORK – II

DOA – 13/9/2010 DOT – 28/9/2010 DOS – 28/9/2010

MM – 25(SUB 7 + TEST 18)

COURSE TUTOR: - Mr Sarabjeet Singh

STUDENT ROLL NO: A32

SECTION NO: D3801

DECLARATION:-

I declare that this assignment is my individual work. I have


not copied from any other students work or from any other source except where
you acknowledgement is made explicitly in the text nor has any part being
written for me by another person.

EVALUATOR’S COMMENT: - STUDENT’S


SIGNATURE:

Darshan
Singh

MARKS:-

OUT OF:-
PART A

Q1: A program using if-then-else statements

If Temperature <30 : Light yellow lamp

If temperature >=30 and <40 : Light green lamp

If Temperature >=40 : Light red lamp

Ans. Default Input port -> FFF8H

Default Output port -> FFFAH

MOV DX, 0FFFEH (point DX to port control register)

MOV AL, 99H (load control word to initialize port)

OUT DX, AL

MOV DX, 0FFF8H

IN AL, DX

CMP AL, 30

JB YELLOW

JMP GREEN

YELLOW: MOV AL, 0IH

MOV DX, 0FFFAH

OUT DX, AL

JMP, EXIT

GREEN: MOV AL, 02H

MOV DX, 0FFFAH

OUT DX, AL

EXIT: MOV DX, 0FFFCH


IN AL, DX

CODE ENDS

END

Q2: Compute the average of 4 bytes stored in an array in memory.

Ans.

Q3: How the near call procedures and far call procedures are different
from each other.

Ans. Far Call Procedure –

1. Far Call Pushes the current value of CS register on the Stack.

2. It pushes the current value of EIP register on the Stack.

3. It also loads the segment selector of the segment that contains the called
procedure in the CS register.

4. It loads the offset of the called procedure in the EIP register.

5. It begins the execution of the called procedure.

Near Call Procedure (within the current code segment) –

1. Near Call procedure pushes the current value of the EIP register on the stack

2. It loads the offset of the called procedure in the EIP register.

3. Begins the execution of the called procedure.


PART B

Q4: Write a program to push and pop some data using assembly language.

Ans. PUSH and POP operation is done in stack. Stack is a place where data is
temporarily stored. The SS and SP registers point to that place like this –

SS: SP So the SS register is the segment and the SP register contains the offset. We
can now use PUSH and POP instruction to this. It will be done like this –

MOV AX, 1234H

PUSH AX

MOV AH, 09

INT 21H

POP AX

The final value of AX will be 1234H. In this we first load 1234H into AX, then we
push that value into the stack. We now store 9 in AH, so AX will be 0934H and
execute INT. The we Pop the AX register. We retrieve the pushed value from the
stack. So Ax contains 1234H again.

Q5: Write the syntax and example of the following instructions

a) CALL b) CMP c)INC d)INT e)JNP/JPO

Ans.

a) CALL instruction

b) CMP instruction is used to compare two operands given and sets/clears the
appropriate flags. For example –

MOV CX, 10

CMPLOOP

DEC AX

CMP AX, 3

LOOPNE CMPLOOP

c) INC instruction

MOV CX, 100


_LABEL:

INC AX

LOOP_LABEL

d) INT instruction

INT 21H

Q6: What are the benefits of using macros in microprocessor and give an
example to show the working of the macro.

Ans. A macro is a gro of repetitive instructions in a program which are copied only
once and can be used as many times as necessary. Here are some of its features -

 It is a method for using repeated group of instructions in case procedure is to


short or not appropriate for procedure .

 It is a group of instructions we bracked and give a name at the start of the


program. Each time we call the macro, the assembler will insert the defined
group of instructions in place of the call.

 Machine code is generated each time macro is called, it is called as


expanding the macro.

 This is inline, there is no need to go to procedure and return.

For example if we want to place the cursor on a determined position on the screen
using macro, we will do it like this –

Position MACRO Row, Column

PUSH AX

PUSH BX

PUSH DX

MOV AH, 02H

MOV DH, Row

MOV DL, Column

MOV BH, 0

INT 10H
POP DX

POP BX

POP AX

ENDM

To use this macro we have to call it by its name as there were other assembler
instructions.

You might also like