Montagem x86: Antes de fazer uma chamada do sistema no Linux Você deve salvar todos os registros?
Eu tenho o código abaixo que abre um arquivo, lê-o em um buffer e depois fecha o arquivo.
A chamada de fechamento do sistema de arquivos requer que o número do descritor de arquivos esteja no registro ebx. O registro ebx obtém o número do descritor de arquivo antes que a chamada de leitura do sistema seja feita. Minha pergunta é: devo salvar o registro ebx na pilha ou em algum lugar antes de fazer a chamada do sistema de leitura (int 80h poderia lixeira no registro ebx?). E, em seguida, restaure o registro ebx para a chamada de sistema fechada? Ou o código que tenho abaixo é seguro e seguro?
Eu executei o código abaixo e ele funciona, apenas não tenho certeza se é geralmente considerado uma boa prática de montagem ou não, porque eu não salvo o registro ebx antes da chamada de leitura int 80h.
;; open up the input file
mov eax,5 ; open file system call number
mov ebx,[esp+8] ; null terminated string file name, first command line parameter
mov ecx,0o ; access type: O_RDONLY
int 80h ; file handle or negative error number put in eax
test eax,eax
js Error ; test sign flag (SF) for negative number which signals error
;; read in the full input file
mov ebx,eax ; assign input file descripter
mov eax,3 ; read system call number
mov ecx,InputBuff ; buffer to read into
mov edx,INPUT_BUFF_LEN ; total bytes to read
int 80h
test eax,eax
js Error ; if eax is negative then error
jz Error ; if no bytes were read then error
add eax,InputBuff ; add size of input to the begining of InputBuff location
mov [InputEnd],eax ; assign address of end of input
;; close the input file
;; file descripter is already in ebx
mov eax,6 ; close file system call number
int 80h