Feeds:
Posts
Comments

Archive for January 3rd, 2019

To get input from user, we can use sys_call no.3 with file descriptor in ebx which is 0 (stdin).
Type the code below, save to input.asm, assemble, link and run.

1 section .text
2 global _start
3 _start:
4 %macro printmsg 2
5 mov eax,4
6 mov ebx,1
7 mov ecx,%1
8 mov edx,%2
9 int 0x80
10 %endmacro
11 %macro getinput 1
12 mov eax,3
13 mov ebx,0
14 mov ecx,name
15 mov edx,10
16 int 0x80
17 %endmacro
18
19 printmsg msg1,lengmsg1 ;enter name
20 getinput name ;get input
21 printmsg msg2,lenmsg2 ;print hello
22 printmsg name,6 ;print name
23 printmsg newline,1 ;new line
24 printmsg msg3,lenmsg3 ;print welcome
25
26 mov eax,1 ;exit
27 int 0x80
28
29 section .data
30 msg1 db 'Please, enter your name (6 chars)?',0xA
31 lengmsg1 equ $ - msg1
32 msg2 db 'Hello '
33 lenmsg2 equ $ - msg2
34 msg3 db 'Welcome to assembly programming',0xA
35 lenmsg3 equ $ - msg3
36 newline db 0xA
37 section .bss
38 name resb 0

Compile and run the program

$ nasm -f elf32 input.asm -o input.o && ld input.o -o input
$ ./input
Please, enter your name (6 chars)?
Taufan
Hello Taufan
Welcome to assembly programming
$

Read Full Post »