Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
4.2 kB
1
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 2000 
	S2: .space 2000
	m2: .space 4 
	n2: .space 4 
	nrv: .space 4
	slash: .asciz "\n"

.text
.global main
main:

    pushl $m
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx
    addl $1, m
    movl %ecx, m2
    addl $1, m
 
    pushl $n
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx
    addl $1, n
    movl %ecx, n2
    addl $1, n

    pushl $p
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx
    movl $0, c

for_vii:

    movl c, %ecx
    cmp %ecx, p
    je for_k

    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
    mull n
    addl j, %eax
    incl %eax

    lea S, %edi
    movl $1, (%edi, %eax, 4)
    incl c
    jmp for_vii

  
for_k:

    pushl $k
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx
    movl $0, c

evolutii:

    movl c, %ecx
    cmp %ecx, k
    je out 
    incl c
    movl $1, i
    
for_line:

    movl i, %ecx
    cmp %ecx, m2
    je transpunere
    movl $1, j
    
for_column:

    movl j, %ecx
    cmp %ecx, n2
    je cont_line

    movl i, %eax
    xor %edx, %edx
    mull n 
    addl j, %eax

    lea S, %edi
    movl (%edi, %eax, 4), %ebx
    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

    cmp $0, %ebx
    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
    cmp $3, %eax
    je cell_invie
    cmp $2, %eax
    je cell_invie
    jmp cell_moare
    
cell_moarta: 

    movl nrb, %eax
    cmp $3, %eax
    je cell_invie
    jmp cell_moare
    
cell_moare:

    movl i, %eax
    xor %edx, %edx
    mull n
    addl j, %eax

    lea S2, %edi
    movl $0, (%edi, %eax, 4)
    jmp cont_column

cell_invie: 
    
    movl i, %eax
	xor %edx, %edx
	mull n
	addl j, %eax
	
    lea S2, %edi
    movl $1, (%edi, %eax, 4)
    jmp cont_column


transpunere:

	movl $1, i
	
for_line_transp:
	
	movl i, %ecx
    cmp %ecx, m2
    je evolutii
    movl $1, j
    
for_column_transp:

    movl j, %ecx
    cmp %ecx, n2
    je cont_line_transp
    movl i, %eax
    xor %edx, %edx
    mull n
    addl j, %eax

    lea S2, %edi
    movl (%edi, %eax, 4), %ebx 
    lea S, %edi
    movl %ebx, (%edi, %eax, 4)

    incl j
    jmp for_column_transp

cont_line_transp:
      
    incl i
    jmp for_column_transp
    jmp evolutii

out:

    movl $1, i

for_i:

    movl i, %ecx
    cmp %ecx, m2
    je exit
    movl $1, j
    
for_j:
            
    movl j, %ecx
    cmp %ecx, n2
    je out_cont

    movl i, %eax
    xor %edx, %edx
    mull n
    addl j, %eax

    lea S , %edi
    movl (%edi, %eax, 4), %ebx

    pushl %ebx
    pushl $formatPrintf
    call printf
    popl %ebx
    popl %ebx

    pushl $0
    call fflush
    popl %edx

    incl j
    jmp for_j

out_cont:

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

    incl i
    jmp for_i


exit:
    mov $1, %eax
    xor %ebx, %ebx
    int $0x80
Leave a Comment