summaryrefslogtreecommitdiff
path: root/nasm/triangle.asm
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2022-12-14 19:55:37 +0800
committergarhve <git@garhve.com>2022-12-14 19:55:37 +0800
commit600bef43c9d67dfcd6a884306c19121bec0235a7 (patch)
treed515a887f3a438a8156f960379bd89795ebd675b /nasm/triangle.asm
parente654642d76e08a6a6b0517022eaeab29c5819c46 (diff)
remove a.out
Diffstat (limited to 'nasm/triangle.asm')
-rw-r--r--nasm/triangle.asm33
1 files changed, 33 insertions, 0 deletions
diff --git a/nasm/triangle.asm b/nasm/triangle.asm
new file mode 100644
index 0000000..a7a443d
--- /dev/null
+++ b/nasm/triangle.asm
@@ -0,0 +1,33 @@
+ global _start
+ section .text
+_start:
+ mov rdx, output ; rdx holds next byte's address to write
+ mov r8, 1 ; initial line length
+ mov r9, 0 ; number of stars written to line so far
+_line:
+ mov byte [rdx], '*' ; write single star to memory at given address in rdx
+ inc rdx ; increase rdx to next call to write
+ inc r9 ; count number so far on line
+ cmp r9, r8 ; compare if stars number exceed line length
+ jne _line ; loop if not yet exceed
+_linedone:
+ mov byte [rdx], 10 ; newline
+ inc rdx ; move rdx to next memory address
+ inc r8 ; increase line length
+ mov r9, 0 ; reset stars number for new line
+ cmp r8, maxlines ; compare if reached max line
+ jng _line ; loop newline
+_done:
+ mov rax, 1 ; invoke system call for write
+ mov rdi, 1 ; file handler 1 is stdout
+ mov rsi, output ; address of string to output
+ mov rdx, datasize ; number of bytes
+ syscall ; invoke OS to write
+ mov rax, 60 ; invoke system call for exit
+ xor rdi, rdi ; exit code 0
+ syscall ; invoke OS to exit
+
+ section .bss
+maxlines: equ 8
+datasize: equ 44
+output: resb datasize