0

It's not a code error as such, but I'm stuck and need help. I try to execute a procedure as many times as I indicate by the keyboard, but when I print a number, for example, four by the keyboard, it only executes the procedure once, I think it is because when I move the content stored in 'text' to the ECX register, the content (4) is identified as a character and not as a number, so the loop instruction just jumps to the procedure and does nothing else. Does anyone know how I can make the program identify the character as a number? Or how to convert from character to number inside the program?

section .data
  error db 'error'
  loner equ $-error
  fproc db 'You have printed the first proc.'
  lon1 equ $-fproc
  sproc db 'You have printed the second proc.'
  lon2 equ $-sproc
section .bss
  text resb 11
section .text
        global _start
_start:
    mov eax, 3
    mov ebx, 0
    mov ecx, text
    mov edx, 11
    int 0x80
_floop:
    mov eax, [text]
    mov ebx, 'loop'
    cmp eax, ebx
    jne _error
_snumb:
    mov esi, text+5
    lodsd
    mov ecx, eax
_compare:
    mov esi, text+7
    lodsd
    mov ebx, 'fpro'
    cmp eax, ebx
    je _loofpro
    jne _secompare
_secompare:
    mov esi, text+7
    lodsd
    mov ebx, 'spro'
    cmp eax, ebx
    je _loospro
    jne _error
_loofpro:
    loop _fpro
    jmp _finalize
_loospro:
    loop _spro
    jmp _finalize
_fpro:
    mov eax, 4
    mov ebx, 1
    mov ecx, fproc
    mov edx, lon1
    int 0x80
_ffinalize:
    jmp _finalize
_spro:
    mov eax, 4
    mov ebx, 1
    mov ecx, sproc
    mov edx, lon2
    int 0x80
_sfinalize:
    jmp _finalize
_error:
    mov eax, 4
    mov ebx, 1
    mov ecx, error
    mov edx, loner
    int 0x80
_finalize:
    mov eax, 1
    mov ebx, 0
    int 0x80 
Michael
  • 57,169
  • 9
  • 80
  • 125
  • 2
    I don't understand why you would need the `lods` instructions for this (or why you're using the dword variant to read a single character). Why not just use something like `movzx ecx, byte [text+5]` ? Followed by `sub ecx, '0'` if you want to convert `'4'` to `4`. – Michael Nov 05 '21 at 06:59
  • It doesn't works. – Alvaro Garcia Nov 05 '21 at 14:49

0 Answers0