Assignment-5 #2

Merged
saschato merged 18 commits from Assignment-5 into master 2024-06-10 14:32:32 +02:00
Showing only changes of commit 452ad7813d - Show all commits

View file

@ -5,15 +5,54 @@
%define O_CREAT 00000100o
%define O_TRUNC 00001000o
%define S_IRUSR 00000400o
%define S_IWUSR 00000200o
%define S_IWUSR 00000200o
section .data
path: db "/home/user/nachricht", 0
greeting: db "hidad!", 0
path: db "/home/user/nachricht", 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
global _start
global _start
_start:
;----------------------------------
nop ; <YOUR CODE HERE>
; ------------ End of file ------------
call _open ; open file
call _write ; write to 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;