[Assignment-5] added solution task 3 (syscalling)

This commit is contained in:
Sascha Tommasone 2024-06-08 18:12:30 +02:00
parent e8894d34d1
commit 452ad7813d
Signed by: saschato
GPG key ID: 751068A86FCAA217

View file

@ -5,15 +5,54 @@
%define O_CREAT 00000100o %define O_CREAT 00000100o
%define O_TRUNC 00001000o %define O_TRUNC 00001000o
%define S_IRUSR 00000400o %define S_IRUSR 00000400o
%define S_IWUSR 00000200o %define S_IWUSR 00000200o
section .data section .data
path: db "/home/user/nachricht", 0 path: db "/home/user/nachricht", 0
greeting: db "hidad!", 0 greeting: db "hidad!", 0
; https://stackoverflow.com/a/45386640
length equ $ - greeting ; Length of greeting message
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86-32_bit;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
section .text section .text
global _start global _start
_start: _start:
;---------------------------------- call _open ; open file
nop ; <YOUR CODE HERE> call _write ; write to file
; ------------ End of file ------------ call _close ; close file
call _exit ; exit without errors
; https://www.man7.org/linux/man-pages/man2/open.2.html
_open:
mov eax, 0x05 ; syscall number for 'open'
mov ebx, path ; pointer to the path string
mov ecx, O_CREAT ; open the file if it doesn't exist
xor ecx, O_WRONLY ; open the file in write-only mode
mov edx, S_IRUSR ; permissions for the file
int 0x80 ; call kernel
; https://man7.org/linux/man-pages/man2/write.2.html
_write:
mov ebx, eax ; file descriptor returned by 'open'
mov eax, 0x04 ; syscall number for 'write'
mov ecx, greeting ; pointer to the greeting message
mov edx, length ; length of the greeting message
sub edx, 0x01 ; length of the greeting message without null byte
int 0x80 ; call kernel
; https://man7.org/linux/man-pages/man2/close.2.html
_close:
mov eax, 0x06 ; syscall number for 'close'
int 0x80 ; call kernel
; https://man7.org/linux/man-pages/man2/exit.2.html
_exit:
mov eax, 1 ; syscall number for 'exit'
mov ebx, 0 ; exit status
int 0x80 ; call kernel
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;