diff options
Diffstat (limited to '')
| -rw-r--r-- | src/outputGenerator.s | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/src/outputGenerator.s b/src/outputGenerator.s deleted file mode 100644 index 1e9224b..0000000 --- a/src/outputGenerator.s +++ /dev/null @@ -1,153 +0,0 @@ -.section .data
-# This buffer holds the ASCII code for tab and newline
-newline:
- .byte 10 # '\n'
-
-tab:
- .byte 9 # '\tab'
-
-.section .text
-# --------------------------------------------
-# FUNCTION: print_tab
-# PURPOSE : print a tab character ('\t')
-# INPUTS :
-# OUTPUTS :
-# CLOBBERS: rax, rdi, rsi, rdx
-# --------------------------------------------
-.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
- syscall
- ret
-
-
-# --------------------------------------------
-# FUNCTION: print_newline
-# PURPOSE : print a newline character ('\n')
-# INPUTS :
-# OUTPUTS :
-# CLOBBERS: rax, rdi, rsi, rdx
-# --------------------------------------------
-.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
- syscall
- ret
-
-
-# --------------------------------------------
-# FUNCTION: print_buffer
-# PURPOSE : take a buffer of coordinates and print each coordinate on a line
-# INPUTS : rdi = pointer to buffer, rsi = number of coordinates
-# OUTPUTS :
-# CLOBBERS: rax, rdi,
-# --------------------------------------------
-.globl print_buffer
-.type print_buffer, @function
-print_buffer:
- cmpq $0, %rsi
- jle done # if n > 0 print_coordinate
-
- 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 1st number from element
- call print_num # Print it
- push %rdx # save pointer
- push %rsi # save n
- call print_tab
- pop %rsi # retrieve n
- pop %rdx # retrieve pointer
-
- # print y and newline
- movq 8(%r15), %rdi # Get the 2nd number
- call print_num # Print it
- push %rdx # save pointer
- push %rsi # save n
- call print_newline
- pop %rsi # retrieve n
- pop %rdx # retrieve pointer
-
-
- # move to next coordinate and decq n
- addq $8, %rdx
- decq %rsi
-
- cmpq $0, %rsi
- jg loop
-
-done:
- ret
-
-
-# --------------------------------------------
-# 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:
- push %rbp
- movq %rsp, %rbp
-
- # save
- push %rax
- push %rdi
- push %rsi
- push %rdx
- push %rcx
- push %r8
- push %r9
-
- 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
- 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
- syscall
- addq $8, %rsp
- addq $-1, %r9
- jne .Lprint_num_printLoop
-
- # restore
- pop %r9
- pop %r8
- pop %rcx
- pop %rdx
- pop %rsi
- pop %rdi
- pop %rax
-
- movq %rbp, %rsp
- pop %rbp
- ret
-
-
|