Another example of basic I/O program in Linux64. This example demonstrates extensive use of basic I/O routines offered by the library;
; Compile: nasm -f elf64 base64x.asm
; Link : ld base64x.o -o base64x
; Execute: ./base64x
global _start
section .bss
theName resb 100 ;allocation for large buffer
gend resb 1
section .data
hello db "Please input your name: ",0
ageStr db "How old are you?: "
hiMr db "Hi Mr ",0
hiMs db "Hi Ms ",0
gender db "Enter gender [m/f]: ",0
age dq 0
section .text
_start:
mov rax,gender ;ask for gender
call prnstrz
call readch ;get the char
call halt ;hold the screen
mov [gend],al ;copy pressed key into a byte var
mov rax,hello ;ask for name
call prnstrz
mov rax,theName ;read the string to buffer
call readstr ;return 0-ended string buffer
mov rbx,18 ;size of string
mov rax,ageStr ;the string to print. Ask for age
call prnstr ;note, this is prnstr, not prnstrz
call readint ;read integer from keyboard. Return in RAX
mov qword[age],rax ;save the result to a variable
mov rax,hiMs ;Decision for salutation. Default case
cmp byte[gend],'f'
je .female
mov rax,hiMr ;Else
.female:
call prnstrz
mov rax,theName
call prnstrz
mov rax,',you`re '
call prnstreg
mov rax,qword[age]
add rax,1
call prnintu
mov rax,' next ye'
call prnstreg
mov rax,'ar'
call prnstreg
call exitx
Hopefully, with this possible output;
Enter gender [m/f]: m
Please input your name: Frank Kotler
How old are you?: 34
Hi Mr Frank Kotler,you`re 35 next year
This example maybe too much for a beginner, but this should give you the basic idea of many things of assembly language, this library and NASM (variables, sections, registers, call instructions, basic anatomy etc).