1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
|