[Assignment-5] added solution task 3 (syscalling)
This commit is contained in:
parent
e8894d34d1
commit
452ad7813d
1 changed files with 46 additions and 7 deletions
|
@ -7,13 +7,52 @@
|
|||
%define S_IRUSR 00000400o
|
||||
%define S_IWUSR 00000200o
|
||||
|
||||
section .data
|
||||
path: db "/home/user/nachricht", 0
|
||||
greeting: db "hidad!", 0
|
||||
|
||||
section .data
|
||||
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
|
||||
_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
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in a new issue