This is a code to add all numbers between 50 and 150 and display the result in decimal form.I have created the stack segment .STACK 32 to store the remainders to convert the hex result to decimal format. The address of data segment is passed to DS. I also need to pass address of stack segment to SS but the error occurs.enter image description here
TITLE ADD 10 NUMBERS FROM 50 TO 150
.MODEL SMALL
.STACK 32
.DATA
ARR DW 60,70,86,79,70,140,130,120,100,150
STRING DB "THE SUM OF NUMBERS IS: $"
SUM DW ?
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AX,@STACK
MOV SS,AX
LEA SI,ARR
MOV AX,0
MOV CX,10
REPEAT:
ADD AX,[SI]
INC SI
INC SI
LOOP REPEAT
MOV DX,0
MOV CX,0
MOV BX,10
REPEAT2:
CMP AX,0
JZ NEXT
DIV BX
PUSH DX
SUB DX,DX
INC CX
JMP REPEAT2
NEXT:
CMP CX,0
JZ EXIT
POP DX
ADD DX,30H
DEC CX
MOV AH,02H
INT 21H
JMP NEXT
EXIT:
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
It works for @data but not for @stack why?
.STACKdirective sets the stack size. 512 would probably be better than 32. However, you're right that generally DOS sets up the stack for an application before transferring control to the application's entry point. Multiple stacks are possible, but unlikely to be needed. And like you wrote, if you setssyou should setspin the very next instruction. (Surrounding a stack change withcliandstiwill do no harm either.)SEGequate likemov ax, SEG stack. Another one that didn't exist in MASM5 was@const