From f07568c5096b33b0b6c3ca80265e173c0eb3b63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Thu, 11 Jan 2024 01:26:42 +0300 Subject: [PATCH] feat: right_triangle --- 009-right_triangle.s | 103 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 009-right_triangle.s diff --git a/009-right_triangle.s b/009-right_triangle.s new file mode 100644 index 0000000..cc9b5e7 --- /dev/null +++ b/009-right_triangle.s @@ -0,0 +1,103 @@ +.global _start +.intel_syntax noprefix +.data + input: + .byte 0x00 + new_line_collector: + .byte 0x00 +.text + _start: + //hello world + lea rsi, [text_hello_world] + mov rdx, 13 + call printf + + lea rsi, [text_how_far_do_you_want_to_go] + mov rdx, 28 + call printf + + lea rsi, [input] + mov rdx, 1 + call scanf + sub input, byte ptr '0' + mov r8b, input + xor r9b, r9b + + upper: + cmp r9b, r8b + jae exit + mov r10b, r9b + add r10b, r10b + add r10b, 1 + call print_stars_of_the_line + call print_new_line + inc r9b + jmp upper + + //exit + exit: + lea rsi, [text_goodbye] + mov rdx, 9 + call printf + mov rax, 60 + xor rdi, rdi + syscall + + text_hello_world: + .asciz "Hello World\n" + text_how_far_do_you_want_to_go: + .asciz "How Far Do You Want to Go = " + text_star: + .asciz "*" + text_space: + .asciz " " + text_new_line: + .asciz "\n" + text_goodbye: + .asciz "\nGoodbye\n" + print_stars_of_the_line: + mov r11b, 0 + cmp r11b, r10b + jae returner + call print_star + dec r10b + jmp print_stars_of_the_line + + returner: + xor rdi, rdi + ret + print_star: + lea rsi, [text_star] + mov rdx, 1 + call printf + xor rdi, rdi + ret + print_space: + lea rsi, [text_space] + mov rdx, 1 + call printf + xor rdi, rdi + ret + print_new_line: + lea rsi, [text_new_line] + mov rdx, 1 + call printf + xor rdi, rdi + ret + printf: + mov rax, 1 + mov rdi, 1 + syscall + xor rdi, rdi + ret + scanf: + mov rax, 0 + mov rdi, 0 + syscall + mov rax, 0 + mov rdi, 0 + mov rsi, [new_line_collector] + mov rdx, 1 + syscall + xor rdi, rdi + ret