This program reads characters from the user as input and stores them on the stack. It then pops the characters off the stack and displays them in reverse order. Specifically:
1) It prompts the user, reads characters into a register until enter is pressed, and pushes each character onto the stack.
2) It pops the characters off the stack and displays them using a loop, outputting the input in reverse order.
3) It terminates the program after displaying the reversed input.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views
Cse 316 (Lab - 4) Reverse Input
This program reads characters from the user as input and stores them on the stack. It then pops the characters off the stack and displays them in reverse order. Specifically:
1) It prompts the user, reads characters into a register until enter is pressed, and pushes each character onto the stack.
2) It pops the characters off the stack and displays them using a loop, outputting the input in reverse order.
3) It terminates the program after displaying the reversed input.
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1
CSE 316 (Lab -4) REVERSE INPUT
TITLE PGM8_1: REVERSE INPUT
.MODEL SMALL .386 .STACK .CODE MAIN PROC ;display user prompt MOV AH,2 ;prepare to display MOV DL,'?' ;char to display INT 21H ;display '?' ;initialize character count XOR CX,CX ;count = 0 ;read a character MOV AH,1 ;prepare to read INT 21H ;read a char ;while character is not a carriage return do WHILE_: CMP AL,0DH ;CR? JE END_WHILE ;yes, exit loop ;save character on the stack and increment count PUSH AX ;push it on stack INC CX ;count = count + 1 ;read a character INT 21H ;read a char JMP WHILE_ ;loop back END_WHILE: ;go to a new line MOV AH,2 ;display char fcn MOV DL,0DH ;CR INT 21H ;execute MOV DL,0AH ;LF INT 21H ;execute JCXZ EXIT ;exit if no characters read ;for count times do TOP: ;pop a character from the stack POP DX ;get a char from stack ;display it INT 21H ;display it LOOP TOP ;end_for EXIT: MOV AH,4CH INT 21H MAIN ENDP END MAIN