You are on page 1of 5

1. What is an assembler?

The dumb translator that will convert these mnemonics back to the original opcodes is a key
program to be used throughout this course and is called the assembler.

2. What is difference b/w zero & carry flag?


The Zero flag is set if the last mathematical or logical instruction has produced a zero in its
destination.
Carry
When two 16bit numbers are added the answer can be 17 bits long or when two 8bit numbers
are added the answer can be 9 bits long. This extra bit that wont fit in the target register is placed
in the carry flag where it can be used and tested.

3. Why do we use segment register?


The segment registers have a very special purpose - pointing at accessible
blocks
of
memory.
Segment registers work together with general purpose register to access any
memory value. For example if we would like to access memory at the physical
address 12345h (hexadecimal), we should set the DS = 1230h and SI =
0045h. This is good, since this way we can access much more memory than
with
a
single
register
that
is
limited
to
16
bit
values.
CPU makes a calculation of physical address by multiplying the segment register
by 10h and adding general purpose register to it (1230h * 10h + 45h =
12345h):

4. Define LEA instruction with example.


LEA
Operand
REG, memory

Load

Effective

Address.

Algorithm:

REG = address of memory (offset)

Generally this instruction is replaced by MOV when assembling when possible.


Example:

#make_COM#
ORG 100h
LEA AX, m
RET
m DW 1234h
END

AX
is
set
to:
0104h.
LEA instruction takes 3 bytes, RET takes 1 byte, we start at 100h, so the address of 'm' is 104h.
CZSOPA
unchanged

5. What is different NEAR anf FAR procedure?


Write a far procedure to reverse an array of 64k words such that the first element becomes the last
and the last becomes the first and so on. For example if the first word contained 0102h, this value
is swapped with the last word. The next word is swapped with the second last word and so on. The
routine will be passed two parameters through the stack; the segment and offset of the first element
of the array.
3. Write a near procedure to copy a given area on the screen at the center of the screen without
using a temporary array. The routine will be passed top, left, bottom, and right in that order through
the stack.
The parameters passed will always be within range the height will be odd and the width will be
even so that it can be exactly centered.

6. Brief describe the purpose of BYTE, WORD and DWORD directive.


Variable is a memory location. For a programmer it is much easier to have
some value be kept in a variable named "var1" then at the address
5A73:235B, especially when you have 10 or more variables.
Our compiler supports two types of variables: BYTE and WORD.
Syntax

for

variable

declaration:

name

DB

value

name

DW

value

DB

stays

for

Define

Byte.

DW

stays

for

Define

Word.

name - can be any letter or digit combination, though it should start with a letter. It's possible
to declare unnamed variables by not specifying the name (this variable will have an address
but
no
name).
value - can be any numeric value in any supported numbering system (hexadecimal, binary,
or decimal), or "?" symbol for variables that are not initialized.

Unsigned

multiply.

Algorithm:
when
AX = AL * operand .

operand

is

byte:

when
operand
(DX AX) = AX * operand .

is

word:

Example:
M O V A L, 200 ; A L = 0C 8h
M O V BL, 4
M U L BL
; A X = 0320h (800)
RE T

CZSOPA
r ? ? r ? ?
CF=OF=0 when high section of the result is zero.
Exchange

values

of

two

operands.

>

operand2

Algorithm:
operand1

<

Example:
M O V A L, 5
M O V A H, 2
X C HG A L, A H ; A L = 2, A H = 5
X C HG A L, A H ; A L = 5, A H = 2
RE T

CZSOPA
unchanged

Subtract.
Algorithm:
operand1

operand1

operand2

Example:
M O V A L, 5
SU B A L, 1

; AL = 4

RE T

CZSOPA
r r r r r r

Procedures
Procedure is a part of code that can be called from your program in order to
make some specific task. Procedures make program more structural and
easier to understand. Generally procedure returns to the same point from
where
it
was
called.
The syntax for procedure declaration:
name

PROC
;
;

here
of

goes
the

the
procedure

code
...

RET
name ENDP

Macros
Macros are just like procedures, but not really. Macros look like procedures,
but they exist only until your code is compiled, after compilation all macros
are replaced with real instructions. If you declared a macro and never used it
in your code, compiler will simply ignore it. emu8086.inc is a good example
of how macros can be used, this file contains several macros to make coding
easier for you.
Macro definition:
nam e

M A C RO [param eters,...]

<in struction s>


ENDM

Unlike procedures, macros should be defined above the code that uses it, for
example:
M yM acro

M A C RO p1, p2, p3

M O V A X, p1
M O V BX , p2
M O V C X , p3
ENDM
O RG 100h
M yM acro 1, 2, 3
M yM acro 4, 5, D X
RE T

You might also like