Assighnment:-2: Omputer Peripherals & Interfaces
Assighnment:-2: Omputer Peripherals & Interfaces
PART A
Ans:-
Ans 2
Code_Seg SEGMENT
Assume DS:data_seg,cs:code_seg
MOV AL,data_seg
MOV DS,AL
ADD Hi_TEMP
MOV BL,02H
DIV BL
Code_Seg ENDS
Q3: How the near call procedures and far call procedures are
different from each other.
Ans 3 The 8086 supports near and far subroutines. Near calls and returns
transfer control between procedures in the same code segment. Far calls
and returns pass control between different segments. The two calling and
return mechanisms push and pop different return addresses
Use the near ptr and far ptr operators to override the automatic
assignment of a near or far call. If NearLbl is a near label and FarLbl is a
far label then the following call instructions generate a near and far call
respectively:
Suppose you need to make a far call to NearLbl or a near call to FarLbl.
You can accomplish this using the following instructions:
Calling a near procedure using a far call or calling a far procedure using a
near call isn't something you'll normally do. If you call a near procedure
using a far call instruction the near return will leave the cs value on the
stack. Generally rather than:
push cs
call NearProc
PART B
Q4: Write a program to push and pop some data using assembly
language.
Ans 4
Push — Push stack (Opcodes: FF, 89, 8A, 8B, 8C, 8E, ...)
The push instruction places its operand onto the top of the hardware
supported stack in memory. Specifically, push first decrements ESP by 4,
then places its operand into the contents of the 32-bit location at address
[ESP]. ESP (the stack pointer) is decremented by push since the x86 stack
grows down - i.e. the stack grows from high addresses to lower addresses.
Syntax
push <reg32>
push <mem>
push <con32>
Examples
push eax — push eax on the stack
push [var] — push the 4 bytes at address var onto the stack
pop — Pop stack
The pop instruction removes the 4-byte data element from the top of the
hardware-supported stack into the specified operand (i.e. register or
memory location). It first moves the 4 bytes located at memory location
[SP] into the specified register or memory location, and then increments
SP by 4.
Syntax
pop <reg32>
pop <mem>
Examples
pop edi — pop the top element of the stack into EDI.
pop [ebx] — pop the top element of the stack into memory at the four
bytes starting at location EBX.
Ans5
Syntax
call <label>
ret
CMP:-Compare
Compare the values of the two specified operands, setting the condition
codes in the machine status word appropriately. This instruction is
equivalent to the sub instruction, except the result of the subtraction is
discarded instead of replacing the first operand.
Syntax
cmp <reg>,<reg>
cmp <reg>,<mem>
cmp <mem>,<reg>
cmp <reg>,<con>
Example
cmp DWORD PTR [var], 10
jeq loop
If the 4 bytes stored at location var are equal to the 4-byte integer
constant 10, jump to the location labeled loop.
INC:- Increment
Syntax
inc <reg>
inc <mem>
Examples
inc DWORD PTR [var] — add one to the 32-bit integer stored at location
var
First you have to specify what to print. This function needs DS:DX to be a
far pointer to where the string is. The string has to be terminated with a
dollar sign ($). This would be easy if DS could be manipulated directly, to
get round this we have to use AX. Later one we will build a program that is
printing a string on the screen.
JNP/JPO:- Purpose: Conditional jump, and the state of the flags is taken
into
account.
Syntax:
JNP label
Ans 6
The main difference between a macro and a procedure is that in the macro
the passage of parameters is possible and in the procedure it is not, this
is only applicable for the TASM - there are other programming languages
which do allow it. At the moment the macro is executed each parameter is
substituted by the name or value specified at the time of the call.
Syntax of a Macro
Position 8, 6