MP Assignment 3
MP Assignment 3
Microprocessor Assignment 3
Procedure and macro
Macro :
Assembler directives: These are the statements that direct the assembler to do something.
As the name says, it directs the assembler to do a task.
Macro and Endm: A Macro is a group of instructions with a name. When a macro is invoked,
the associated set of instructions is inserted in place into the source, replacing the macro
name. We could consider the macro as shorthand for a piece of text; somewhat like a new
pseudo code instruction. A macro has a name. The body of the macro is defined between a
pair of directives, MACRO and ENDM. ENDM indicates the end of macro
For e.g. print macro
msg Write code
endm
An instruction of a computer is a command given to the computer to perform a
specified operation on given data. In microprocessor, the instruction set is the collection of
the instructions that the microprocessor is designed to execute. The programmer writes a
program in assembly language using these instructions.
Repne: Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
Scasb: Used to scan a string and compare its byte with a byte in AL.
Procedure :
Assembler Directives:
• Org:
The origin directive sets the location counter to a value specified.
➢ The following statements are assigned memory locations starting with the new
location counter value.
The location counter is a counter in the assembly language program that is used
to assign storage addresses for the program.
As the program is assembled, the location counter keeps track of the current
location in the storage.
➢ This counter is a software construct defined in the assembly program and exists
only during assembly process. It is not the same as program counter. - Ex:
Org 008H
This directive sets the location counter to the value 008H in the data segment.
Procedure assembler directive is used to define a procedure.
A procedure is similar to a function in programming languages. The procedure can
be called
anywhere in the program once defined.
Depending on the location of the definition of procedure, the calls are said to be
near or far calls. -
1
Name- Tanmay Keny Roll no.- 29 XIE I’d- 202001053
Snytax:
Procedure_name proc [type]
ret
Procedure_name endp
-Ex:
Fact proc
back :
mul cx
loop back
ret
fact endp
This statement defines a procedure named fact.
• Endp:
Procedures defined with the proc statement must be terminated by the endp
statement, preceded by the procedure name procedwe_name.
Instruction:
➢ Call:
The call instruction calls near procedures using a full pointer. Call causes the
procedure named in the operand to be executed.
✓ When the called procedure completes, execution flow resumes at the
instruction following the call instruction.
✓ Ex: Call fact
✓ This calls the procedure fact, that is the program jumps to the fact procedure
and on completion of the procedure, the normal execution flow resumes at
the following instruction (here mov result Ox)
➢ Ret:
✓ The ret instruction transfers the control to the return address located on the stack.
This address is usually placed on the stack by a call instruction.
The ret instruction within the called procedwe is issued to resume execution flow
at the instruction following the call instruction.
➢ Loop:
The loop instruction is a combination of decrement counter, test and jump
instruction.
It uses the values in the CX register as a counter, so a repeat count must be initially
loaded into it.
✓ When the loop instruction is executed, it first decrements CX. Then it tests to see
if CX = 0. If CX is not 0, loop transfers control to the displacement specified as its
operand.
There are various versions of loop instruction with some variations on the jump
part, like LOOPZ/ LOOPE (when the zero flag is 1/when the operands are equal),
LOOPNZ/LOOPNE(when the zero flag is O/ when the operands are not equal).
Ex:
Loop back
Here the loop statement will execute the code/ instructions while we under
the label back until cx=0.
2
Name- Tanmay Keny Roll no.- 29 XIE I’d- 202001053