Here we are going to write a simple assembly language program to ask an user to type his name and display his name with Welcome greetings.

Sir is told us not to use printf statement of gcc multillib so we are not going to use this printf in this example.

Here is the link of the code  https://gist.github.com/1594788

section .data
; Declare/store the information “Hello World!”
prompt db ‘What is your name? ‘
; do not change the order of the following three lines!
helloMsg dq ‘Hello ‘
name db ‘ ‘ ; space characters
endOfLine db ‘!’
; do not change the order of the previous three lines!
section .text
global _start
_start:
; Output the information ‘What is your name? ‘
mov eax, 4 ; write…
mov ebx, 1 ; to the standard output (screen/console)…
mov ecx, prompt ; the information at memory address prompt
mov edx, 19 ; 19 bytes (characters) of that information
int 0x80 ; invoke an interrupt
; Accept input and store the user’s name
mov eax, 3 ; read…
mov ebx, 1 ; from the standard input (keyboard/console)…
mov ecx, name ; storing at memory location name…
mov edx, 23 ; 23 bytes (characters) is ok for my name
int 0x80
; Output that information “Hello…”
mov eax, 4 ; write…
mov ebx, 1 ; to the standard output (screen/console)…
mov ecx, helloMsg ; the information at helloMsg…
mov edx, 23 ; 23 bytes (characters) is ok for my name
int 0x80
; Exit
mov eax, 1 ; sys_exit
mov ebx, 0 ; exit status. 0 means “normal”, while 1 means “error”
int 0x80
To compile and run this program
$nasm -f elf greet.asm
$ld -s -o greet greet.o
$./greet
What is your name? Sanjib Narzary //this is input
Hello Sanjib Narzary //this is ouput
$
Thats all. Now your task is to ask user to type two numbers and add them and display the result. 🙂
Advertisements