Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prompt a User to type his name and Gree Him on the Console, Assembly Language Code
;Author : Sanjib Narzary
;Institute: NIT Calicut
;Email: o-._.-o@live.com
;greet.asm
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 that 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"
; see http://en.wikipedia.org/wiki/Exit_status
int 0x80
@sanjibnarzary

This comment has been minimized.

Copy link
Owner Author

sanjibnarzary commented Jan 11, 2012

to run it
$nasm -f elf greet.asm
$ld -s -o greet greet.o
$./greet
What is your name? sanjib narzary
Hello sanjib narzary
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.