Could someone help me with this program in nasm?

0

When I try to read from the keyboard a number of 2 digits and then try to print that number again on the screen it does not return the same value, but if I define the number myself if it works, what am I doing wrong?

segment .data
segment .bss
  datos resb 2
  aux resb 2
segment .text
global _start
_start:
  ;SYSCALL
  mov eax, 3
  mov ebx, 0
  mov ecx, aux
  mov edx, 2
  int 0x80

  mov edx, 0  
  ;mov eax, 55 ; DEFINIENDO EL VALOR SI SE MUESTRA CORRECTAMENTE
  mov eax, [aux]; USANDO EL VALOR ALMACENADO EN AUX NO SE MUESTRA CORRECTAMENTE
  mov ecx, 10
  ; SE REALIZA UNA DIVISION ENTRE 10 PARA TRABAJAR CON NUMEROS DE 2 DIGITOS
  div ecx
  ; SE LE SUMA AL RESIDUO Y AL COCIENTE '0' PARA PODER IMPRIMIR EN PANTALLA CADA UNO DE LOS DIGITOS
  add eax, '0'
  mov [datos+0], eax
  add edx, '0'
  mov [datos+1], edx
  ;SYSCALL
  mov eax, 4
  mov ebx, 0
  mov ecx, datos
  mov edx, 2
  int 80h
_salir:
   mov eax, 1
   xor ebx, ebx
   int 0x80

If someone could help me I would appreciate it

    
asked by Daniel 29.05.2018 в 12:57
source

1 answer

2

The problem is that what you have in aux is not the number typed in binary, but the sequence of characters ascii that the user typed.

Assuming that they are only two characters and both are digits, the following fragment would serve to read them and leave in EAX (in AL actually) the number they represent:

  mov eax, 0      ; Borrar parte alta del registro por si acaso
  mov al, [aux]   ; Leemos el primer dígito (ascii)
  sub al, '0'     ; sustraemos el ascii del cero
  mov ecx, 10
  mul cl          ; y multiplicamos por 10
  mov bl, [aux+1] ; Leemos el segundo dígito (ascii)
  sub bl, '0'     ; restarle el ascii del 0
  add al, bl      ; y añadirlo a lo que teníamos en al
    
answered by 29.05.2018 / 13:27
source