F
F
fsociety_one2020-06-23 00:58:17
assembler
fsociety_one, 2020-06-23 00:58:17

Why is there an infinite loop?

Hello to all collectors, who can tell me why cellValues ​​goes into an infinite loop?

section .text
        global _start    

_start:
        mov     edx, lenBT
        mov     ecx, borderTop
        mov     ebx, 1
        mov     eax, 4
        int     0x80

        mov     cx, 3
cellValues:
        mov     edx, lenBM
        mov     ecx, borderMiddle
        mov     ebx, 1
        mov     eax, 4
        int     0x80
        loop    cellValues

        mov     edx, lenBB
        mov     ecx, borderBottom
        mov     ebx, 1
        mov     eax, 4
        int     0x80

        mov     eax, 1   
        int     0x80  

section .data
        field times 9 db 'X'

        borderTop db    '***** ***** *****', 0dh, 0ah, '*   * *   * *   *', 0xa
        lenBT equ $ - borderTop
        
        borderMiddle db '* '
        lenBM equ $ - borderMiddle

        borderBottom db '*   * *   * *   *', 0dh, 0ah, '***** ***** *****', 0xa
        lenBB equ $ - borderBottom

        num resb 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-06-23
@fsociety_one

mov     cx, 3
cellValues:
        mov     edx, lenBM
        mov     ecx, borderMiddle
        mov     ebx, 1
        mov     eax, 4
        int     0x80
        loop    cellValues

I thought cx is rubbing from ecx

It rubs, and not cx, but ecx. And you need to initialize and save / restore ecx, because in 32-bit code ecx works as a counter for the loop opcode.
On the other hand, the use of the loop opcode seems to be an anachronism these days. If there is a register that is not changed by a system call, it is better to use it and make explicit dec and jnz.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question