Cod sursa(job #2530882)

Utilizator Dinu_BlanovschiDinu Blanovschi Dinu_Blanovschi Data 25 ianuarie 2020 13:44:16
Problema A+B Scor 0
Compilator c-64 Status done
Runda Arhiva de probleme Marime 1.63 kb
.text
	.comm read, 24
	.comm FILE_IN, 8
	.comm FILE_OUT, 8
.section .rodata

digits: .ascii "0123456789"
PATH_IN: .asciz "adunare.in"
PATH_OUT: .asciz "adunare.out"

.text
.globl main

_print_x:
	pushq %rax
	pushq %rdx
	movq $10, %r8
	xorq %rdx, %rdx
	divq %r8
	test %rax, %rax
	jz _print_x.l1
	callq _print_x@PLT
_print_x.l1:
	movq $1, %rax
	movq FILE_OUT@GOTPCREL(%rip), %rdi
	movq (%rdi), %rdi
	movq digits@GOTPCREL(%rip), %rsi
	addq %rdx, %rsi
	movq $1, %rdx
	syscall
	popq %rdx
	popq %rax
	ret

parse_int:
	movq $0, %rax
parse_int.l2:
	movq read@GOTPCREL(%rip), %rcx
	movb (%rcx, %rdi), %cl
	cmpb $0, %cl
	je parse_int.l1
	cmpb $32, %cl
	je parse_int.l1
	cmpb $'\n', %cl
	je parse_int.l1

	subb $'0', %cl
	movq $10, %r8
	mulq %r8
	
	movzbq %cl, %rcx
	addq %rcx, %rax
	incq %rdi
	jmp parse_int.l2
parse_int.l1:
	ret

_error:
	neg %rax
	movq %rax, %rdi
	movq $60, %rax
	syscall

main:
	movq $2, %rax
	movq PATH_IN@GOTPCREL(%rip), %rdi
	movq $0, %rsi
	syscall
	orq %rax, %rax
	js _error
	movq FILE_IN@GOTPCREL(%rip), %rbx
	movq %rax, (%rbx)

	movq $2, %rax
	movq PATH_OUT@GOTPCREL(%rip), %rdi
	movq $577, %rsi
	movq $0644, %rdx
	syscall
	orq %rax, %rax
	js _error
	movq FILE_OUT@GOTPCREL(%rip), %rbx
	movq %rax, (%rbx)

	movq $0, %rax
	movq FILE_IN@GOTPCREL(%rip), %rdi
	movq (%rdi), %rdi
	movq read@GOTPCREL(%rip), %rsi
	movq $23, %rdx
	syscall

	movq $0, %rdi
	callq parse_int

	pushq %rax
	incq %rdi

	callq parse_int

	addq (%rsp), %rax

	callq _print_x

	movq $3, %rax
	movq FILE_IN@GOTPCREL(%rip), %rdi
	movq (%rdi), %rdi
	syscall
	
	movq $3, %rax
	movq FILE_OUT@GOTPCREL(%rip), %rdi
	movq (%rdi), %rdi
	syscall
	
	movq $60, %rax
	xorq %rdi, %rdi
	syscall