I wanted to understand how does a single character input work in x86 assembly, the following snippet of a program does the necessary input, but I would like a deeper explanation of how exactly it works. ( This is linux environment, hence interrupt code is 128 )
sys_exit equ 1
sys_read equ 3
sys_write equ 4
stdin equ 0
stdout equ 1
segment .bss
num1 resb 2
num2 resb 2
res resb 1
...
segment .text
mov eax,std_read
mov ebx,stdin
mov ecx,num1
mov edx,2
int 128
I don't exactly understand how the input mechanism work here ( of course abstractly ) for example, I imagine it to be,
first
eax
is loaded with read system call code, then std input file descriptor is loaded intoebx
.
now this is the part that I don't understand num1
is afterall an address how does loading it into ecx
will receive the input from std input device? what buffering does mov ebx,stdin
do if any? and how does the system know at this line, at which address the input character must be loaded, my best guess is it must have a pointer relative to .bss
section and it keeps receiving the input. but then it gives rise to another question that how do we know if uninitialized data is stored sequentially, Is it? please help me understand.