Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.4 kB
1
Indexable
Never
s: .space 1600
sCopy: .space 1600
formatScanf: .asciz "%ld"
formatPrintf: .asciz "%ld "
newLine: .asciz "\n"
rows: .space 4
rows2: .space 4
cols: .space 4
cols2: .space 4
pairs: .space 4
leftVal: .space 4
rightVal: .space 4
currentIndex: .space 4
currentRow: .space 4
currentCol: .space 4
iterations: .space 4
leftBound: .space 4
rightBound: .space 4
neighbours: .space 4
matrixDim: .space 4

.text
.global main
main:
    pushl $rows
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    pushl $cols
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    pushl $pairs
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

    lea s, %edi
    lea sCopy, %esi

    movl rows, %eax
    movl %eax, rows2
    movl cols, %eax
    movl %eax, cols2
    addl $2, rows2
    addl $2, cols2

    xorl %edx, %edx
    movl rows2, %eax
    mull cols2
    movl %eax, matrixDim

    xorl %ecx, %ecx
initMatrixLoop:
    cmp %ecx, matrixDim
    je endInitMatrixLoop

    movl $0, (%edi, %ecx, 4)
    incl %ecx
    jmp initMatrixLoop

endInitMatrixLoop:

    movl $0, currentIndex
    readPairsLoop:
        movl currentIndex, %ecx
        cmp pairs, %ecx
        je endReadPairsLoop

        pushl $leftVal
        pushl $formatScanf
        call scanf
        popl %ebx
        popl %ebx

        pushl $rightVal
        pushl $formatScanf
        call scanf
        popl %ebx
        popl %ebx

        movl leftVal, %eax
        incl %eax
        xor %edx, %edx
        mull cols2
        addl rightVal, %eax
        incl %eax
        movl $1, (%edi, %eax, 4)

        incl currentIndex
        jmp readPairsLoop

endReadPairsLoop:

    pushl $iterations
    pushl $formatScanf
    call scanf
    popl %ebx
    popl %ebx

endReadK:

    movl $0, currentIndex
    iterateKLoop:
        movl currentIndex, %ecx
        cmp iterations, %ecx
        je endIterationsLoop

        xorl %ecx, %ecx
resetCopyMatrix:
        cmp %ecx, matrixDim
        je endResetCopyMatrix

        movl $0, (%esi, %ecx, 4)
        incl %ecx
        jmp resetCopyMatrix

endResetCopyMatrix:

        movl $1, currentRow
forRow:
        movl currentRow, %ecx
        cmp rows, %ecx
        jg endForRow

        movl $1, currentCol
        forCol:
            movl currentCol, %ecx
            cmp cols, %ecx
            jg endForCol

            movl currentRow, %eax
            xor %edx, %edx
            mull cols2
            addl currentCol, %eax

            pushl (%edi, %eax, 4)
            pushl $formatPrintf
            call printf
            popl %ebx
            popl %ebx

            pushl $0
            call fflush
            popl %ebx

            incl currentCol
            jmp forCol

        endForCol:

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

        incl currentRow
        jmp forRow

    endForRow:

    xorl %ecx, %ecx
copyBackLoop:
    cmp %ecx, matrixDim
    je endCopyBackLoop

    movl (%esi, %ecx, 4), %eax
    movl %eax, (%edi, %ecx, 4)

    incl %ecx
    jmp copyBackLoop

endCopyBackLoop:

    incl currentIndex
    jmp iterateKLoop

endIterationsLoop:

end:
    movl $1, %eax
    xor %ebx, %ebx
    int $0x80
Leave a Comment