Skip to content

Instantly share code, notes, and snippets.

@sanjibnarzary
Created January 11, 2012 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sanjibnarzary/1594788 to your computer and use it in GitHub Desktop.
Save sanjibnarzary/1594788 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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