Why is not printing the numbers in nasm?

0

I'm working in assembly language,in the following program I just want to check if the buffer has numbers and print them but if the buffer has some operation sign if just print which operation is found, but the problem is with the numbers, they are not printed.

sys_exit        equ     1
sys_read        equ     3
sys_write       equ     4
stdin           equ     0 
stdout          equ     1
stderr          equ     3

SECTION     .data
szName          db      "What is your operation? "
Name_Len        equ     $-szName
badExprMsg    db "Invalid expression supplied", 0h
lenbad          equ $-badExprMsg
badOpMsg      db "Unknown character: ", 0h
lenopbd     equ $-badOpMsg

lsuma       db "Suma", 0h
sumlen     equ $-lsuma
lresta       db "Resta", 0h
restalen     equ $-lresta
lmult       db "Multiplicar",0h
multlen     equ $-lmult
ldiv       db "Division"
divlen     equ $-ldiv

SECTION     .bss
lpBuffer        resb    20
Buf_Len         equ     $-lpBuffer

SECTION     .text
global      _start

_start:
mov     ecx, szName
mov     edx, Name_Len
call    DisplayText

mov     ecx, lpBuffer
mov     edx, Buf_Len
call    ReadText

mov esi, ecx
mov edi, eax
add edi, esi

readbuffer:
mov al, [esi]

cmp    al, 43          ; "+"
je     suma
cmp    al, 45          ; "-" 
je     resta
cmp    al, 47          ; "/"
je     division
cmp    al, 120         ; "x"
je     multiplicar        
cmp    al, 48          ; "0"
jl     fail
cmp    al, 57          ; "9"
jg     fail

and eax, 00FFh
mov ecx, eax ; for example ECX : 0x31('1')
mov edx, 1
call DisplayText ; The problem is here after int 0x80 EAX: 0xfffffff1

inc  esi
cmp esi, edi

jb readbuffer

jmp Exit

suma:
mov ecx, lsuma
mov edx, sumlen
call DisplayText
jmp    Exit

resta:
mov ecx, lresta
mov edx, restalen
call DisplayText
jmp    Exit

multiplicar:
mov ecx, lmult
mov edx, multlen
call DisplayText
jmp    Exit

division:
mov ecx, ldiv
mov edx, divlen
call DisplayText
jmp    Exit

fail: 
; An invalid character was supplied as input
mov edx, lenbad
mov ecx, badOpMsg
jmp    Exit

DisplayText:
mov     eax, sys_write
mov     ebx, stdout
int     80H 
ret

ReadText:
mov     ebx, stdin
mov     eax, sys_read
int     80H
ret

Exit:  
mov     eax, sys_exit
xor     ebx, ebx
int     80H

I don't kwow why after calling DisplayText, in register EAX I got a large number instead of the length of a single byte. Hope someone could help me. Thanks in advance.

assembly
x86
nasm
asked on Stack Overflow Oct 12, 2019 by Soichiru

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0