U
U
user.2019-02-18 23:19:00
assembler
user., 2019-02-18 23:19:00

Can someone explain in detail how this NASM code works?

Knowledgeable people tell me as much as possible in detail how this code works. I would be glad if someone will come out to explain complex things in simple words.
I'm not sure that I understand correctly how system functions are accessed through interrupts ... each function has its own h code? I suppose so ... therefore, the arguments in them are always transferred in advance to well-defined registers by means of mov.

; секция определения переменных
SECTION .DATA
  hello:     db 'Hello world!',10
  helloLen:  equ $-hello

; Насколько я понял... точка входа
SECTION .TEXT
  GLOBAL _start 

_start:
  mov eax,4            ; 'write' system call = 4     если верно понял то вызываем api функцию для записи
  mov ebx,1            ; file descriptor 1 = STDOUT
  mov ecx,hello        ; string to write         записываем нашу строку в регистр ECX
  mov edx,helloLen     ; length of string to write   пишем длину нашей строки в регистр EDX
  int 80h              ; call the kernel    здесь все это выполняем посредством вызова необходимого прерывания?

  ; Terminate program   заканчиваем программу
  mov eax,1            ; 'exit' system call          ; передаем аргументы в нашу будущую функцию? 
  mov ebx,0            ; exit with error code 0  ; передаем аргументы в нашу будущую функцию? 
  int 80h              ; call the kernel                ;вызываем нашу функцию посредством вызова необходимого прерывания?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2019-02-18
@nekolov

Calling the system function 80p - *nix syscall
https://syscalls.kernelgrok.com/
You need to pass a descriptor of a file opened for writing, a string to write, the size of the string in characters.
In the register eax set the function number (4 = sys_write)
In ebx file descriptor (in this case 1 - STDOUT, that is, output to the console)
In ecx a reference to the string
In edx - the length of the string.
The string is displayed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question