MPL A1
MPL A1
HADAPSAR, PUNE-28
ASSIGNMENT NO. 1
TITLE: Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from
the user and store them in an array and display the accepted numbers.
OBJECTIVES:
1. To be familiar with the format of assembly language program structure and
instructions.
2. To learn the procedure of how to accept N numbers from the user through an input
device like keyboard and store them in an array using Assembly Language
programming in NASM.
3. To learn the procedure of how to display N numbers stored in an array using
Assembly Language programming in NASM.
PROBLEM DEFINITION:
Write an Assembly language program (ALP) to accept five 64 bit Hexadecimal numbers
from the user, store them in an array and display the accepted numbers
WORKING ENVIRONMENT:
Software Requirements
1. CPU: Intel I5 Processor
2. OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
3. Editor: gedit, GNU Editor
4. Assembler: NASM (Netwide Assembler)
THEORY
Assembly language Program is mnemonic representation of machine code.
Three assemblers available for assembling the programs for IBM-PC are:
Sys_read:
MOV RAX,0
MOV RDI,0
MOV RSI,array_name
MOV RDX,array_size
SYSCALL
Sys_exit:
MOV RAX,60
MOV RDI,0
SYSCALL
Assembly Variables
NASM provides various define directives for reserving storage space for
variables. The define
Assembler directive is used for allocation of storage space. It can be used to
reserve as well as initialize one or more bytes.
• To execute : ./hello
It runs the .exe file to execute the program
Instructions needed:
1. MOV- Transfers a byte, word or double word from the source operand to
the destination operand
2. ADD- Adds specified byte to byte or word to word and stores the result
of addition in the first operand or source register
3. DEC-Decrements specified byte/word by1
4. JNZ- unconditional jump instruction which transfers the control to the
specified label in the program to enable the repetitive execution of the
instructions within the loop formed by this instruction
ALGORITHM:
1. Start
2. Declare an array to store five 64 bit numbers under the BSS
section by reserving memory for it using an appropriate
reserve directive
3. Set the counter to 05 to accept these five numbers one by
one, set a pointer to the array.
4. Accept the number from the user through an input device
like keyboard using read system call
5. Store this number in the array
6. Increment the pointer to access its next location to store the
next number in the array
7. Decrement the counter
8. If counter is not zero go to step 4
9. Reset the pointer to the array such that it points to its first
location
10. Reset the counter to 05 to access these five numbers stored
in the array and display them one by one
11. Display the number from the array using the write system
call
12. Increment the pointer to this array to access and display the
next number
13. Decrement the counter
14. If counter is not zero go to step 11
15. Write the exit system call to exit from the program
16. Stop
Flowchart:
TEST CASES:
1. Take any three examples which explains how the user can give the input
of five 64 bit numbers and store them in the array.
2. The same five numbers getting displayed at the output when the array is
displayed indicates that the numbers have been successfully stored in the
array and can be accessed.
CONCLUSION
1) What is assembler & Linker. Which file is converted into which file by
assembler & Linker ?
2) Steps to execute a NASM Program ?
3) What are different Assembler Directives ?
4) What is dd, dw, db, dq, dt, resb, resw etc ?
5) What is .data section, .bss section, .text section?
6) Explain System calls for Exit, Read, Write for a 64 bit program.
7) How can one access the numbers stored in an array?
8) What is the use of a counter In the program?