Assuming a x86-64 architecture
- Write an assembly program that takes one string parameter and prints it the other way around. (so when started with
abc
, it would printcba
- Write an assembly program that takes two parameters and it creates a hard link with the second parameter as the new name and the first parameter as the file that to be pointed
- Write an assembly program that takes two parameters and it creates a symbolic link with the second parameter as the new name and the first parameter as the file that to be pointed
- Create a program which gets two integer parameters (one digits only) and prints the larger
Last active
November 13, 2023 11:41
-
-
Save Malix-off/033a443379d42fdaad060662572fdfae to your computer and use it in GitHub Desktop.
L3-Hungary - Operating System - Assembly 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
input db "abc", 0 | |
output db 0 | |
section .text | |
global _start | |
_start: | |
; Find the length of the string | |
mov rsi, input ; rsi points to the string | |
xor rcx, rcx ; counter for string length | |
find_length: | |
cmp byte [rsi + rcx], 0 | |
je reverse_string | |
inc rcx | |
jmp find_length | |
; Reverse the string | |
reverse_string: | |
mov rdi, rcx ; rdi points to the end of the string | |
dec rdi ; move rdi to the last character | |
reverse_loop: | |
cmp rsi, rdi | |
jge print_result | |
mov al, [rsi + rcx] | |
mov ah, [rsi + rdi] | |
mov [rsi + rcx], ah | |
mov [rsi + rdi], al | |
inc rsi | |
dec rdi | |
jmp reverse_loop | |
print_result: | |
; Print reversed string | |
mov eax, 1 ; syscall: write | |
mov edi, 1 ; file descriptor: STDOUT | |
mov edx, rcx ; length of the reversed string | |
sub edx, 1 ; exclude the null terminator | |
mov rsi, input | |
syscall ; invoke syscall | |
; Exit the program | |
mov eax, 60 ; syscall: exit | |
xor edi, edi ; status: 0 | |
syscall ; invoke syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
old_file db "source.txt", 0 | |
new_link db "hardlink.txt", 0 | |
section .text | |
global _start | |
_start: | |
; Create a hard link | |
mov rax, 86 ; syscall: link | |
mov rdi, old_file ; source file | |
mov rsi, new_link ; new link file | |
syscall ; invoke syscall | |
; Exit the program | |
mov rax, 60 ; syscall: exit | |
xor rdi, rdi ; status: 0 | |
syscall ; invoke syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
old_file db "source.txt", 0 | |
new_link db "symlink.txt", 0 | |
section .text | |
global _start | |
_start: | |
; Create a symbolic link | |
mov rax, 88 ; syscall: symlink | |
mov rdi, old_file ; source file | |
mov rsi, new_link ; new link file | |
syscall ; invoke syscall | |
; Exit the program | |
mov rax, 60 ; syscall: exit | |
xor rdi, rdi ; status: 0 | |
syscall ; invoke syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
prompt db "Enter first digit: ", 0 | |
prompt2 db "Enter second digit: ", 0 | |
larger_msg db "Larger digit: ", 0 | |
newline db 10 | |
buffer resb 5 | |
section .text | |
global _start | |
_start: | |
; Get the first digit | |
mov rax, 1 ; syscall: write | |
mov rdi, 1 ; file descriptor: STDOUT | |
mov rsi, prompt | |
mov rdx, 20 ; length of the prompt | |
syscall ; invoke syscall | |
; Read the first digit | |
mov rax, 0 ; syscall: read | |
mov rdi, 0 ; file descriptor: STDIN | |
mov rsi, buffer | |
mov rdx, 5 ; maximum number of bytes to read | |
syscall ; invoke syscall | |
; Convert ASCII to integer | |
movzx rax, byte [buffer] | |
sub rax, '0' | |
mov rbx, rax ; store the first digit | |
; Get the second digit | |
mov rax, 1 ; syscall: write | |
mov rdi, 1 ; file descriptor: STDOUT | |
mov rsi, newline | |
mov rdx, 1 ; length of newline | |
syscall ; invoke syscall | |
mov rax, 1 ; syscall: write | |
mov rdi, 1 ; file descriptor: STDOUT | |
mov rsi, prompt2 | |
mov rdx, 20 ; length of the prompt | |
syscall ; invoke syscall | |
; Read the second digit | |
mov rax, 0 ; syscall: read | |
mov rdi, 0 ; file descriptor: STDIN | |
mov rsi, buffer | |
mov rdx, 5 ; maximum number of bytes to read | |
syscall ; invoke syscall | |
; Convert ASCII to integer | |
movzx rax, byte [buffer] | |
sub rax, '0' | |
; Compare and print the larger digit | |
mov rax, 1 ; syscall: write | |
mov rdi, 1 ; file descriptor: STDOUT | |
mov rsi, larger_msg | |
mov rdx, 13 ; length of the message | |
syscall ; invoke syscall | |
cmp rax, rbx | |
jge print_rax | |
mov rax, rbx | |
print_rax: | |
add rax, '0' | |
mov rdi, rax | |
; Print the larger digit | |
mov rax, 1 ; syscall: write | |
mov rdi, 1 ; file descriptor: STDOUT | |
mov rsi, rdi | |
mov rdx, 1 ; length of the digit | |
syscall ; invoke syscall | |
; Exit the program | |
mov rax, 60 ; syscall: exit | |
xor rdi, rdi ; status: 0 | |
syscall ; invoke syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment