program reverseString ; Program accepts a string, then reverses it. It exits when only the ENTER key is pressed. ; Grant Palin ; Created: 2003-01-16 ; Last modified: 2003-01-23 stack 100 CONSOLE EQU 1 GETSTR EQU 1 PUTCHAR EQU 2 PUTSTR EQU 3 EXIT EQU 0xffff ;Code to finish program data input db 81, [?] * 82 ;Define the input size intro1 db "Program accepts a string up 80 characters. Type something, then press ENTER.", 0 intro2 db "To exit, just press ENTER.", 0 prompt db "Enter a string: ", 0 ;Define the prompt newline db 10, 13, 0 ;Define a new line and carriage return code reverseString ;Program start point mov PUTSTR, r1 ;Intro line 1 lea intro1, r2 sys CONSOLE mov PUTSTR, r1 ;Print a line break lea newline, r2 sys CONSOLE mov PUTSTR, r1 ;Intro line 2 lea intro2, r2 sys CONSOLE mov PUTSTR, r1 ;Print a line break lea newline, r2 sys CONSOLE START mov PUTSTR, r1 ;Print prompt on screen lea prompt, r2 sys CONSOLE ;Prompt for string mov GETSTR, r1 ;Accept string from keyboard lea input, r2 sys CONSOLE lodbs input + 1, , r3 ;Load length of string into register 3 cmp r3, 0 ;Compare the length of the string to zero be Finish ;If they are equal, the user did not type a ;string, so exit program ;Output result mov PUTSTR, r1 ;Print the input string lea input+2, r2 sys CONSOLE mov PUTSTR, r1 ;Print a line break lea newline, r2 sys CONSOLE REVERSE cmp r3, 0 ;Compare contents of register 3 with zero be NEW ;If they are equal, jump to NEW lodbl input+1, r3, r2 ;Add 1 and length of string and puts result into register 2 mov PUTCHAR, r1 sys CONSOLE ;Print the last character in the string at position input+1+r3 dec r3 ;Decrease length value in r3 by 2 bits, so we can access the previous character br REVERSE ;Loops NEW mov PUTSTR, r1 ;Print a line break lea newline, r2 sys CONSOLE br START ;Jump to the beginning to do it all over again Finish mov PUTSTR, r1 ;Print a line break lea newline, r2 sys CONSOLE sys EXIT ;Program will end end