.section .data 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 # keep pointer here, rdi will be used for print_num loop: # print x and tab movq (%rdx), %rdi # load x call print_num 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(%rdx), %rdi # load y call print_num 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 $16, %rdx decq %rsi cmpq $0, %rsi jg loop done: ret # Print RDI as an unsigned integer without any new line. # 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