.
MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'Computer', '$' ; Original string (ends with $)
LEN DW 6 ; Length of the string
.CODE
MAIN PROC
MOV AX, @DATA ; Initialize Data Segment
MOV DS, AX
MOV SI, OFFSET STR1 ; SI points to the start of the string
MOV CX, LEN ; Load loop counter with string length
; --- Step 1: Push characters onto the Stack ---
PUSH_LOOP:
MOV AL, [SI] ; Get character
PUSH AX ; Push onto stack (Note: PUSH works on 16-bit)
INC SI ; Move to next character
LOOP PUSH_LOOP
; --- Step 2: Pop characters back to String ---
MOV SI, OFFSET STR1 ; Reset SI to start of string
MOV CX, LEN ; Reset loop counter
POP_LOOP:
POP AX ; Pop top of stack (last character pushed)
MOV [SI], AL ; Overwrite string memory with the character
INC SI ; Move to next position
LOOP POP_LOOP
; --- Step 3: Display the reversed string ---
MOV DX, OFFSET STR1 ; Load address for DOS display function
MOV AH, 09H ; DOS string output function
INT 21H
; --- Exit Program ---
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN