cfcfcsf

mail@pastecode.io avatar
unknown
plain_text
2 months ago
5.0 kB
1
Indexable
Never
.data
formatScanf: .asciz "%d\n"
formatPrintf: .asciz "%d\n"
slash: .asciz "\n"
m: .space 4
n: .space 4
p: .space 4
k: .space 4
i: .space 4
j: .space 4
S: .space 500
Ss: .space 500
cell: .space 4
nrv: .space 4

.text
.global main
main: 
    # Citeste m
    pushl $m
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    # Citeste n
    pushl $n
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    # Citeste p
    pushl $p
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    movl $0, %ecx

for_vii:
    movl %ecx, %eax
    cmpl %eax, p
    je evolutii_cont

    # Citeste i
    pushl $i
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    # Citeste j
    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 %ecx
    jmp for_vii

evolutii_cont:
    movl $0, %ecx

evolutii:
    # Citeste k
    pushl $k
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    movl %ecx, %eax
    cmpl %eax, k
    je out

    movl $1, i

for_line:
    movl i, %eax
    cmpl m, %eax
    jg transpunere
    movl $1, j

for_column:
    movl i, %eax
    cmpl m, %eax
    jg cont_line

    movl i, %eax
    xor %edx, %edx
    movl n, %ebx
    addl $2, %ebx
    mull %ebx
    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
    lea S, %edi
    movl (%edi, %eax, 4), %edx
    addl %edx, nrv

    # i-1, j
    movl i, %eax
    xor %edx, %edx
    decl %eax
    mull n
    addl j, %eax
    lea S, %edi
    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
    lea S, %edi
    movl (%edi, %eax, 4), %edx
    addl %edx, nrv

    # i, j+1
    movl i, %eax
    xor %edx, %edx
    mull n
    addl j, %eax
    incl %eax
    lea S, %edi
    movl (%edi, %eax, 4), %edx
    addl %edx, nrv

    # i, j-1
    movl i, %eax
    xor %edx, %edx
    mull n
    addl j, %eax
    decl %eax
    lea S, %edi
    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
    lea S, %edi
    movl (%edi, %eax, 4), %edx
    addl %edx, nrv

    # i+1, j
    movl i, %eax
    xor %edx, %edx
    incl %eax
    mull n
    addl j, %eax
    lea S, %edi
    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
    lea S, %edi
    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, %eax
    cmpl m, %eax
    jg cont_evolutie
    movl $1, j

for_column_2:
    movl j, %eax
    cmpl n, %eax
    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 %ecx
    jmp evolutii

out:
    movl $1, i

for_line_3:
    movl i, %eax
    cmpl m, %eax
    jg exit

    movl $1, j

for_column_3:
    movl j, %eax
    cmpl n, %eax
    jg cont_out

    movl $1, %ebx
    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