Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.8 kB
2
Indexable
Never
.data 
	formatScanf: .asciz "%d\n"
	formatPrintf: .asciz "%d\n"
	m: .space 4
	n: .space 4
	p: .space 4
	k: .space 4
	i: .space 4
	j: .space 4
	c: .space 4
	S: .space 500
	Ss: .space 500
	cell: .space 4
	nrv: .space 4
	slash: .asciz "\n"
.text
.global main
main: 
	pushl $m
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx
	
	pushl $n
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx
	
	pushl $p
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx

	movl $0, c
	
for_vii:
	
	movl c, %ecx
	cmpl %ecx, p
	je evolutii_cont
	
	pushl $i
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx
	
	pushl $j
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx
	
	movl i, %eax
	incl %eax
	xorl %edx, %edx
	movl n, %ebx
	addl $2, %ebx
	mull %ebx
	incl %eax
	addl j, %eax
	lea S, %edi
	movl $1, (%edi, %eax, 4) 
	
	incl c
	jmp for_vii
	
evolutii_cont:
	
	movl $0, c
	
evolutii:

	pushl $k
	pushl $formatScanf
	call scanf
	popl %ebx
	popl %ebx
	
	
	movl c, %ecx
	cmpl %ecx, k
	je out
	movl $1, i
	
for_line:
	
	movl i, %ecx
	cmpl m, %ecx
	jg transpunere
	movl $1, j
	
for_column: 

	movl i, %ecx
	cmpl m, %ecx
	jg cont_line
	
	movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	
	lea S, %edi
	movl (%edi, %eax, 4), %ebx
	movl %ebx, cell
	movl $0, nrv
	//i-1,j-1
	movl i, %eax
	xor %edx, %edx
	decl %eax
	mull n
	addl j, %eax
	decl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i-1, j
	movl i, %eax
	xor %edx, %edx
	decl %eax
	mull n
	addl j, %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i-1,j+1
	movl i, %eax
	xor %edx, %edx
	decl %eax
	mull n
	addl j, %eax
	incl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i,j+1
	movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	incl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i, j-1
	movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	decl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i+1,j+1
	movl i, %eax
	xor %edx, %edx
	incl %eax
	mull n
	addl j, %eax
	incl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i+1,j
	movl i, %eax
	xor %edx, %edx
	incl %eax
	mull n
	addl j, %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	//i+1,j-1
	movl i, %eax
	xor %edx, %edx
	incl %eax
	mull n
	addl j, %eax
	decl %eax
	movl (%edi, %eax, 4), %edx
	addl %edx, nrv
	
	cmpl $0, nrv
	je cell_moarta
	jmp cell_vie
	
cont_column:
	
	incl j
	jmp for_column
	
cont_line:

	incl i
	jmp for_line
	
cell_vie: 
	
	movl nrv, %eax
	cmpl $3, %eax
	je cell_invie
	
	cmpl $2, %eax
	je cell_invie	
	
	jmp cell_moare	
	
cell_moarta:
	
	movl nrv, %eax
	cmpl $3, %eax
	je cell_invie
	jmp cell_moare
	

cell_invie:

	movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	
	lea Ss, %edi
	movl $1, (%edi, %eax, 4)
	
	jmp cont_column
	
cell_moare:
	
	movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	
	lea Ss, %edi
	movl $0, (%edi, %eax, 4)
	jmp cont_column
	
transpunere:

	movl $1, i
	
for_line_2:
	
	movl i, %ecx
	cmpl m, %ecx
	jg cont_evolutie
	movl $1, j
	
for_column_2:

	movl j, %ecx
	cmpl n, %ecx
	jg cont_line_2
	
	movl i, %eax
	xor %edx, %edx
	movl n, %ebx
	addl $2, %ebx
	mull %ebx
	addl j, %eax
	
	lea Ss, %edi
	movl (%edi, %eax, 4), %ebx
	lea S, %edi
	movl %ebx, (%edi, %eax, 4)
	
	incl j
	jmp for_column_2
	
cont_line_2:
	
	incl i
	jmp for_line_2
	
cont_evolutie:

	incl c
	jmp evolutii
	
out:
	movl $1, i
	
for_line_3:

	movl i, %ecx
	cmpl m, %ecx
	jg exit
	movl $1, j
	
for_column_3:

	movl j, %ecx
	cmpl n, %ecx
	jg cont_out
	
	movl 1, %eax
	movl $0, %edx
	addl $2, %ebx
	mull %ebx
	addl j, %eax
	
	lea S, %edi
	movl (%edi, %eax, 4), %ebx
	
	pushl %ebx
	pushl $formatPrintf
	call printf
	popl %ecx
	popl %ecx
	
	pushl $0
	call fflush
	popl %ecx
	
	incl j
	jmp for_column_3

cont_out:

	movl $4, %eax
        movl $1, %ebx
        movl $slash, %ecx
        movl $2, %edx
        int $0x80

        incl i
        jmp for_line_3
	
exit:
	mov $1, %eax
	mov $0, %ebx
	int $0x80
	
Leave a Comment