diff options
Diffstat (limited to '')
| -rw-r--r-- | src/outputGenerator.s | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/src/outputGenerator.s b/src/outputGenerator.s index 34377ba..1e9224b 100644 --- a/src/outputGenerator.s +++ b/src/outputGenerator.s @@ -1,4 +1,5 @@ .section .data
+# This buffer holds the ASCII code for tab and newline
newline:
.byte 10 # '\n'
@@ -16,10 +17,10 @@ tab: .globl print_tab
.type print_tab, @function
print_tab:
- movq $1, %rax # write
- movq $1, %rdi # stdout
- movq $tab, %rsi # load tab character
- movq $1, %rdx # 1 byte
+ movq $1, %rax # write
+ movq $1, %rdi # stdout
+ movq $tab, %rsi # load tab character
+ movq $1, %rdx # 1 byte
syscall
ret
@@ -34,10 +35,10 @@ print_tab: .globl print_newline
.type print_newline, @function
print_newline:
- movq $1, %rax # write
- movq $1, %rdi # stdout
- movq $newline, %rsi # load newline character
- movq $1, %rdx # 1 byte
+ movq $1, %rax # write
+ movq $1, %rdi # stdout
+ movq $newline, %rsi # load newline character
+ movq $1, %rdx # 1 byte
syscall
ret
@@ -55,13 +56,13 @@ print_buffer: cmpq $0, %rsi
jle done # if n > 0 print_coordinate
- movq %rdi, %rdx # keep pointer here, rdi will be used for print_num
+ movq %rdi, %rdx # save pointer, rdi is used for print_num
loop:
movq (%rdx), %r15 # Pointer element
# print x and tab
- movq (%r15), %rdi # Get first number from element
+ movq (%r15), %rdi # Get 1st number from element
call print_num # Print it
push %rdx # save pointer
push %rsi # save n
@@ -70,7 +71,7 @@ loop: pop %rdx # retrieve pointer
# print y and newline
- movq 8(%r15), %rdi # Get the second number
+ movq 8(%r15), %rdi # Get the 2nd number
call print_num # Print it
push %rdx # save pointer
push %rsi # save n
@@ -78,6 +79,7 @@ loop: pop %rsi # retrieve n
pop %rdx # retrieve pointer
+
# move to next coordinate and decq n
addq $8, %rdx
decq %rsi
@@ -89,9 +91,16 @@ done: ret
-# Print RDI as an unsigned integer without any new line.
+# --------------------------------------------
+# FUNCTION: print_num
+# PURPOSE : print rdi as an unsigned integer
+# INPUTS : rdi
+# OUTPUTS :
+# CLOBBERS:
# Note: the function does not follow the ordinary calling convention,
# but restores all registers.
+# --------------------------------------------
+
.type print_num, @function
.globl print_num
print_num:
@@ -107,22 +116,22 @@ print_num: push %r8
push %r9
- movq %rdi, %rax # arg
- movq $0, %r9 # digit count
+ movq %rdi, %rax # arg
+ movq $0, %r9 # digit count
.Lprint_num_convertLoop:
movq $0, %rdx
movq $10, %rcx
idivq %rcx
- addq $48, %rdx # '0' is 48
+ addq $48, %rdx # '0' is 48
push %rdx
addq $1, %r9
cmpq $0, %rax
jne .Lprint_num_convertLoop
.Lprint_num_printLoop:
- movq $1, %rax # sys_write
- movq $1, %rdi # stdout
- movq %rsp, %rsi # buf
- movq $1, %rdx # len
+ movq $1, %rax # sys_write
+ movq $1, %rdi # stdout
+ movq %rsp, %rsi # buf
+ movq $1, %rdx # len
syscall
addq $8, %rsp
addq $-1, %r9
|