Created
January 11, 2012 14:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Author : Sanjib Narzary | |
;Institute: NIT Calicut | |
;Email: [email protected] | |
;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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to run it
$nasm -f elf greet.asm
$ld -s -o greet greet.o
$./greet
What is your name? sanjib narzary
Hello sanjib narzary
$