I have this RPN calculator program in TASM that calculates an expression in the string data_stack:
.model small
.stack 100h
.data
data_stack db '3 4 +', 0
top equ 0
result db 0
.code
start:
mov ax, @data
mov ds, ax
mov bx, offset data_stack
mov cl, 1
read_argument:
mov dx, [bx]
cmp dx, 0
je calculate_result
push dx
inc cl
inc bx
jmp read_argument
calculate_result:
jmp calculate_expression
calculate_expression:
pop bx
mov al, [bx]
cmp al, '+'
je add_operands
cmp al, '-'
je subtract_operands
add_operands:
pop bx
add al, [bx]
jmp calculate_expression
subtract_operands:
pop bx
sub al, [bx]
jmp calculate_expression
print_result:
mov ah, 02h
mov dl, al
int 21h
exit_program:
mov ah, 4Ch
int 21h
end start
But it crashes in debugging mode at line:
mov bx, offset data_stack
I work in DOSBox and I don't know the reason, so should I use another register or what?
I tested few rpn strings and debugger shows good results. It works with digits
1 - 9and result should be in range-128,255. Each character in string is separated by space (20h). I also addedflagin cl register just to make sure that stack contains 2 values.https://www-stone.ch.cam.ac.uk/documentation/rrf/rpn.html