Assignment No.: 01: Name: Shraddha Umesh Mulay Roll No.: 221083 GR No.: 22020260 Sy-A
Assignment No.: 01: Name: Shraddha Umesh Mulay Roll No.: 221083 GR No.: 22020260 Sy-A
Assignment No.: 01: Name: Shraddha Umesh Mulay Roll No.: 221083 GR No.: 22020260 Sy-A
Assignment No.: 01
Title: Basics of Assembly Language
Objectives:
1) To study assembly language
2) To study different system calls
3) To study the instruction set
Theory:
2) Linker: Linker is a program in a system which helps to link a object modules of program into
a single object file. It performs the process of linking. Linker are also called link editors.
Linking is process of collecting and maintaining piece of code and data into a single file.
Linker also link a particular module into system library. It takes object modules from
assembler as input and forms an executable file as output for loader.
Linking is performed at both compile time, when the source code is translated into
machine code and load time, when the program is loaded into memory by the loader.
Linking is performed at the last step in compiling a program.
Linking is of two types:
1. Static Linking -
It is performed during the compilation of source program. Linking is performed
before execution in static linking. It takes collection of relocatable object file and
command-line argument and generate fully linked object file that can be loaded and
run.
Static linker perform two major task:
Symbol resolution – It associates each symbol reference with exactly one
symbol definition .Every symbol have predefined task.
Relocation – It relocate code and data section and modify symbol references
to the relocated memory location.
The linker copy all library routines used in the program into executable image. As a
result, it require more memory space. As it does not require the presence of
2. Dynamic linking-
Dynamic linking is performed during the run time. This linking is accomplished by
placing the name of a shareable library in the executable image. There is more
chances of error and failure chances. It require less memory space as multiple
program can share a single copy of the library.
ENDP Directive: This directive is used along with the name of the procedure to
indicate the end of a procedure to the assembler. The PROC and ENDP directive are
used to bracket a procedure.
Advantages:
1) Allows to save memory space.
2) Program development becomes easier.
3) Debugging of errors in program become easy.
Disadvantages:
1) CALL and RET instructions are always required to integrate with procedures.
2) Requires the extra time to link procedure and return from it.
3) For small group of instructions, linking and returning back time more than the
execution time, hence for small group of instructions procedures cannot be preffered.
Macro : A MACRO is group of small instructions that usually performs one task. It is
a reusable section of a software program.A macro can be defined anywhere in a
program using directive MACRO &ENDM.
Disadvantages:
1) object code is generated every time a macro is called hence object file becomes
lengthy.
2) For large group of instructions macro cannot be preferred.
8) Compiling and Linking in Assembly Program:Make sure you have set the path
of nasm and ld binaries in your PATH environment variable.
Now, take the following steps for compiling and linking the above program −
Type the above code using a text editor and save it as hello.asm.
Make sure that you are in the same directory as where you saved hello.asm.
To assemble the program, type nasm -f elf hello.asm
If there is any error, you will be prompted about that at this stage. Otherwise, an object
file of your program named hello.o will be created.
To link the object file and create an executable file named hello, type ld -m elf_i386 -
s -o hello hello.o
Execute the program by typing ./hello
If you have done everything correctly, it will display 'Hello, world!' on the screen.
9) Linux Assembly System Calls: You can make use of Linux system calls in your
assembly programs. You need to take the following steps for using Linux system calls
in your program −
MOV − Used to copy the byte or word from the provided source to the provided
destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT − Used to translate a byte in AL using a table in the memory.
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
Arithmetic: These instructions are used to perform arithmetic operations like addition,
subtraction, multiplication, division, etc.
Following is the list of instructions under this group −
DIV − Used to divide the unsigned word by byte or unsigned double word by word.
IDIV − Used to divide the signed word by byte or signed double word by word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower
byte.
CWD − Used to fill the upper word of the double word with the sign bit of the lower
word.
Bit Manipulation:
These instructions are used to perform operations where data bits are involved, i.e.
operations like logical, shift, etc.
Following is the list of instructions under this group −
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into
the new MSB.
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry
Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to
Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
Program Execution Transfer Instructions: These instructions are used to transfer/branch
the instructions during an execution. It includes the following instructions −
Instructions to transfer the instruction during an execution without any condition −
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next instruction.