error when trying to move the first byte from a string into a register

588 views Asked by At

I'm pretty new at masm and I need to make a pocket calculator. I have done the macros for +, -, /, * and i'm putting my expression in the EBX register.

for example: I type "1 + 2 =" and the EBX takes all that string and stores it.

I'm trying to take every character and store it in CL so that I can call the macro after that. I have found the expression mov cl, byte ptr[ebx]

But right here my program crashes. I have no idea what's wrong. Here is my code:

    zecimal read:
push offset expr
push offset expr_format
call scanf
add esp,8

mov al,output
mov bl,change ;to change the base ex. Zecimal - Z, Hexa - H
mov ecx,expr

cmp al,cl
jz end      ;if input = "exit"

cmp bl,cl
jz read_loop            ;changes base if = "num"

mov ebx,0       ;reset ebx
mov ecx,0       ;reset ecx

mov ebx,expr        ;replace expr in ebx
mov eax,0           ;reset eax

alloc:
mov ecx,0

mov cl,byte ptr[ebx] ;read 1st char from the string <--- THIS IS MY PROBLEM

    cmp cl,' '      ;comp with spce
jz space        

mul ten
sub cl,'0'
add ax,cx
inc ebx
jmp alloc

space: <-- this is where i compare the sign with my operators
    .....

I have searched everywhere and found nothing. PLEASE HELP :(

1

There are 1 answers

0
Michael On BEST ANSWER

In the alloc loop you're reading from [ebx], and right before the start of the loop you set ebx to expr. You haven't shown the declaration of expr or explained what it's supposed to be, but I'm going to guess that it's an array of bytes that you use to hold a string. In that case, the line mov ebx, expr should be mov ebx, offset expr