Accept and Display Numbers
Accept and Display Numbers
EXP NO: 01
AIM: : Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from user and store them in an
array and display the accepted numbers.
OBJECTIVES:
To apply instruction set for implementing X86/64 bit assembly language programs
ENVIRONMENT:
THEORY:
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 1s and 0s. 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. Assembly language is a low-level programming language for a computer, or other programmable
device specific to particular computer architecture in contrast to most high-level programming languages,
which are generally portable across multiple systems. Assembly language is converted into executable
machine code by a utility program referred to as an assembler like NASM, MASM etc.
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
Installing NASM:
If you select "Development Tools" while installed Linux, you may NASM installed along with the
Linux operating system and you do not need to download and install it separately. For checking
whether you already have NASM installed, take the following steps:
If it is already installed then a line like, nasm: /usr/bin/nasm appears. Otherwise, you will see
The order in which these sections fall in your program really isn’t important, but by convention the
.data section comes first, followed by the .bss section, and then the .text section.
The .data section contains data definitions of initialized data items. Initialized data is data that has a
value before the program begins running. These values are part of the executable file. They are loaded
into memory when the executable file is loaded into memory for execution. You don’t have to load
them with their values, and no machine cycles are used in their creation beyond what it takes to load the
program as a whole into memory. The important thing to remember about the .data section is that the
more initialized data items you define, the larger the executable file will be, and the longer it will take to
load it from disk into memory when you run it.
Not all data items need to have values before the program begins running. When you’re reading data
from a disk file, for example, you need to have a place for the data to go after it comes in from disk.
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
Data buffers like that are defined in the .bss section of your program. You set aside some number of
bytes for a buffer and give the buffer a name, but you don’t say what values are to be present in the
buffer. There’s a crucial difference between data items defined in the .data section and data items defined
in the .bss section: data items in the .data section add to the size of your executable file. Data items in
the .bss section do not.
The actual machine instructions that make up your program go into the .text section. Ordinarily, no data
items are defined in .text. The .text section contains symbols called labels that identify locations in the
program code for jumps and calls, but beyond your instruction mnemonics, that’s about it.
All global labels must be declared in the .text section, or the labels cannot be ‘‘seen’’ outside your
program by the Linux linker or the Linux loader. Let’s look at the labels issue a little more closely.
Labels
A label is a sort of bookmark, describing a place in the program code and giving it a name that’s easier
to remember than a naked memory address. Labels are used to indicate the places where jump instructions
should jump to, and they give names to callable assembly language procedures.
Labels must begin with a letter, or else with an underscore, period, or question mark. These last
three have special meanings to the assembler, so don’t use them until you know how NASM
interprets them.
Labels must be followed by a colon when they are defined. This is basically what tells NASM
that the identifier being defined is a label. NASM will punt if no colon is there and will not flag
an error, but the colon nails it, and prevents a mistyped instruction mnemonic from being
Labels are case sensitive. So yikes:, Yikes:, and YIKES: are three completely different labels.
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
Macros
ALGORITHM:
INPUT: ARRAY
OUTPUT: ARRAY
STEP 1: Start.
FLOWCHART:
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
PROGRAM:
section .data
section .bss
counter resb 1
section .text
global _start
_start:
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg1
mov Rdx,len1
syscall
;accept
mov byte[counter],05
mov rbx,00
loop1:
add rsi,rbx
Progressive Education Society's
Modern College of Engineering, Pune-05.
DEPARTMENT OF COMPUTER ENGINEERING
mov rdx,17
syscall
dec byte[counter]
JNZ loop1
;display
mov Rax,1
mov Rdi,1
mov Rsi,msg2
mov Rdx,len2
syscall
;display
mov byte[counter],05
mov rbx,00
loop2:
add rsi,rbx
syscall
add rbx,17
dec byte[counter]
JNZ loop2
mov rdi,0
syscall
;output
:~$ cd ~/Desktop
Desktop$ ./ass1
;23
;34
;45
;56
;23
;34
;45
;56
CONCLUSION:
In this practical session we learnt how to write assembly language program and Accept and display array
in assembly language.
Oral Question