简体   繁体   中英

Loop doesn't work, nasm

I made a program to output counts from 1-9, but after compiling I only get a "0". I have no idea, where I made a mistake. I would like to ask for help. Below I place a code:

section .text
global _start

_start:
        xor esi,esi
        mov esi,[variable]

_middle:
        mov [variable],esi

        mov eax,4
        mov ebx,1
        mov ecx,variable
        mov edx,[length]
        int 80h

        inc esi

        cmp esi,57
        jbe _middle

_end:
        mov eax,1
        int 80h

section .data

variable        db      48
length  dd      $-variable

You increment esi but you forget to store it into variable , so at the top of the loop the original value is read again. Move the line that stores esi after the label _middle . (And you don't need the line to retrieve variable into esi anymore.)

As it seems you are working with ASCII values, you should not start variable with the value 0 but with 48 :

_start:
        mov esi, 48
_middle:
        mov esi,[variable]

Alternatively, start with variable initialized:

variable        db      '0'

but that requires some more rewriting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM