Assembly level language,Assembly level language detail explanation.
Size: 342.58 KB
Language: en
Added: Nov 02, 2015
Slides: 22 pages
Slide Content
Assembly Language Programming
What is Assembly Language?
= Each personal computer has a microprocessor that manages the
computer's arithmetical, logical and control activities.
æ Each family of processors has its own set of instructions for handling
various operations like getting input from keyboard, displaying
information on screen and performing various other jobs.
= These set of instructions are called machine language instruction’.
= Processor understands only machine language instructions which are
strings of Is and Os. However machine language is too obscure and
complex for using in software development. So the low level assembly
language is designed for a specific family of processors that represents
various instructions in symbolic code and a more understandable form.
Advantages of Assembly Language
An understanding of assembly language provides knowledge of:
Interface of programs with OS, processor and BIOS;
Representation of data in memory and other external devices;
How processor accesses and executes instruction;
How instructions accesses and process data;
How a program access external devices.
Other advantages of using assembly language are:
It requires less memory and execution time;
It allows hardware-specific complex jobs in an easier way;
It is suitable for time-critical jobs;
Assemblers
Assemblers need to
= translate assembly instructions and pseudo-instructions into
machine instructions.
= Convert decimal numbers, etc. specified by programmer into
binary
Typically, assemblers make two passes over the assembly file
= First pass: reads each line and records labels in a symbol table
æ Second pass: use info in symbol table to produce actual
machine code for each line
Linker
+ Tool that merges the object files produced by separate compilation or
assembly and creates an executable file.
+ Three tasks
Searches the program to find library routines used by program, e.g.
printf), math routines,...
Determines the memory locations that code from each module will
occupy and relocates its instructions by adjusting absolute references.
Resolves references among files
Debuggers
A program needed when writing any type of code
Displays the contents of memory
Lets you view registers and variables and see how they change
Allows tracing (stepping through a program one line at a time) .
A debugger supplied with both DOS and Windows
Debug.exe
Found in \Windows\command
Command line driven
A precursor of Microsoft Codeview, Borland Turbo Debugger, Visual Studio
Debuggers, Periscope, Atron, SYMDEB, Codesmith-86, Advanced-Trace-86
Assembly Level Debugger
™ Debug is an assembly level debugger
"Displays only assembly mnemonics and machine instructions.
C> debug sample.exe
0000
Prepored by patthore
Debugging Functions
= Assemble short programs
= View a program’s source code along with its machine language
= View the CPU registers and flags
® Trace or execute a program, watching variables for changes
= Enter new values into memory
® Search for binary or ASCII values in memory
æ Move a block of memory from one location to another
® Fill a block of memory
w Load and write disk files and sectors
Procedure
= Definition of procedure
® A procedure is a collection of instructions to which we can direct the
flow of our program, and once the execution of these instructions is
over control is given back to the next line to process of the code
which called on the procedure.
® Procedures help us to create legible and easy to modify programs.
= At the time of invoking a procedure the address of the next
instruction of the program is kept on the stack so that, once the flow
of the program has been transferred and the procedure is done, one
can return to the next line
of the original program, the one which called the procedure.
Procedure
= A procedure begins with the PROC directive and ends with the ENDP directive.
® each directive appears with the procedure name
= PROC is followed by the type of procedure:
w NEAR or FAR
= In MASM version 6.x, the NEAR or FAR type can be followed by the USES
statement.
= USES allows any number of registers to be automatically pushed to the stack
and popped from the stack within the procedure
CALE
= Transfers the flow of the program to the procedure.
® CALL instruction differs from the jump instruction because a CALL
saves a return address on the stack.
= The return address returns control to the instruction that
immediately follows the
CALL in a program when a RET instruction executes.
NEAR CALL
| æ 3 bytes long.
= the first byte contains the opcode; the second
and third bytes contain the displacement
= When the near CALL executes, it first pushes the offset address of the next
instruction onto the stack.
= offset address of the next instruction appears in the instruction pointer (IP or
EIP)
= It then adds displacement from bytes 2 & 3
to the IP to transfer control to the procedure.
= Why save the IP or EIP on the stack?
= the instruction pointer always points to the
next instruction in the program
® For the CALL instruction, the contents of IP/EIP are pushed onto the stack.
® program control passes to the instruction following the CALL after a procedure
ends.
GAR CALE
® 5-byte instruction contains an opcode followed by the next value for the IP and CS
registers.
® bytes 2 and 3 contain new contents of the IP
æ bytes 4 and 5 contain the new contents for CS
1 Far CALL places the contents of both IP and CS on the stack before jumping to the address
indicated by bytes 2 through 5.
= This allows far CALL to call a procedure located anywhere in the memory and return from
that procedure.
= The program branches to the procedure.
® A variant of far call exists as CALLF, but should be avoided in favor of defining the
type of call instruction with the PROC statement
= In 64-bit mode a far call is to any memory location and information placed onto the stack is
an 8-byte number.
= the far return instruction retrieves an 8-byte return address from the stack and places it
red, ito-RIP
Memory Initialization/Reservation
These directives will initialize or reserve memory space in the
form of a byte, a word, or a double word in the code space.
The directives for memory initialization and reservation are DB,
DW and DD
These directives will initialize and reserve memory storage in the
form of a byte, a word or a double word in code space
The directive to reserve memory without initialization is DS
This directive will reserve specified number of bytes in the
current segment
DB (Define Byte)
= The DB directive initializes code memory with a byte value
= The directive has the following format:
<label>: DB <expression>, <expression>, ...
label
is the starting address where the byte values are stored
expression
is the byte value, it can be a character string, a symbol, or an 8-bit
constant
DB (Define Byte)
= Example:
CSEGAT 200H
MSG: DB ‘Please enter your password’,
ARRAY: DB 10H,20H,30H,40H,50H
= The above string of characters will be stored as ASCII bytes starting from location
200H, which means location [200H]=50H, [201H]=6CH and so on
= Notice that the DB directive can only be declared in a code segment
= If it is defined in a different segment, the assembler will generate an error
DW (Define Word)
The DW directive initializes the code memory with a double byte or a 16-bit word
The directive has the following format:
<label>: DW <expression>, Sexpression>, ..
Example:
32 words allocated
CNTVAL: DW 1025H, 2340H
310 values of 1234H starting from location XLOC
XLOC: DW 10 DUP (1234H)
The DUP operator can be used to duplicate a sequence of memory contents
The DW directive can only be used in the code segment
“w TPitis defined in other segments, the assembler will give an
error message
DD (Define Double Word)
The DD directive initializes the code memory with double word or 32-bit data
value
The location counter of the segment is incremented by one byte every
time the DS statement is encountered in the program
æ The programmer should be aware that no more than 16 byte values
should be entered starting from the address ‘Input’ as shown in the
above example
æ Notice that the bytes are not initialized, just reserved
Macro
5 = Definition of the macro
® A macro is a group of repetitive instructions in a program which are
codified only once and can be used as many times as necessary.
= 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.
æ We can say then that a procedure is an extension of a determined program,
while the macro is a module with specific functions which can be used by
different programs.
= Another difference between a macro and a procedure is the way of calling
each one, to call a procedure the use of a directive is required, on the
other hand the call of macros is done as if it were an assembler
‘instruction.