User input/Text: Difference between revisions

Example added in PDP-10 assembly (MACRO-10/TOPS-20).
No edit summary
(Example added in PDP-10 assembly (MACRO-10/TOPS-20).)
Line 1,472:
CheckIt
</lang>
 
=={{header|MACRO-10}}==
<lang MACRO-10>
TITLE User Input
 
COMMENT !
User Input ** PDP-10 assembly language (kjx, 2022)
Assembler: MACRO-10 Operating system: TOPS-20
 
This program reads a string (maximum of 80 characters) and
a decimal number. The number is checked to be 75000. Invalid
input (like entering characters instead of a decimal number)
is detected, and an error message is printed in that case.
!
 
SEARCH MONSYM,MACSYM
.REQUIRE SYS:MACREL
 
STDAC. ;Set standard register names.
 
STRING: BLOCK 20 ;20 octal words = 80 characters.
NUMBER: BLOCK 1 ;1 word for number.
 
;;
;; Execution starts here:
;;
 
GO:: RESET% ;Initialize process.
 
;; Print prompt:
 
HRROI T1,[ASCIZ /Please type a string, 80 chars max.: /]
PSOUT%
;; Read string from terminal:
 
HRROI T1,STRING ;Pointer to string-buffer.
MOVEI T2,^D80 ;80 characters max.
SETZ T3 ;No special ctrl-r prompt.
RDTTY% ;Read from terminal.
ERJMP ERROR ; On error, go to ERROR.
 
;; Print second prompt:
 
NUMI: HRROI T1,[ASCIZ /Please type the decimal number 75000: /]
PSOUT%
;; Input number from terminal:
MOVEI T1,.PRIIN ;Read from terminal.
MOVEI T3,^D10 ;Decimal input.
NIN% ;Input number.
ERJMP ERROR ; On error, go to ERROR.
;; Make sure number is actually 75000.
CAIE T2,^D75000 ;Compare number...
JRST [ HRROI T1,[ASCIZ /Number is not 75000! /]
PSOUT% ; ...complain and
JRST NUMI ] ; try again.
MOVEM T2,NUMBER ;Store number if correct.
 
;; Now print out string and number:
 
HRROI T1,STRING ;String ptr into T1.
PSOUT% ;Print string.
 
MOVEI T1,.PRIOU ;Print on standard output.
MOVE T2,NUMBER ;Load number into T2.
MOVEI T3,^D10 ;Decimal output.
NOUT% ;And print the number.
ERJMP ERROR ; On error, go to ERROR.
 
;; End program:
 
HALTF% ;Halt program.
JRST GO ;Allow for 'continue'-command.
 
;;
;; The following routine prints out an error message,
;; similar to perror() in C:
;;
 
ERROR: MOVEI T1,.PRIOU ;Standard output.
MOVE T2,[.FHSLF,,-1] ;Own program, last error.
SETZ T3, ;No size-limit on message.
ERSTR% ;Print error-message.
JFCL ; Ignore errors from ERSTR.
JFCL ; dito.
HALTF% ;Halt program.
JRST GO ;Allow for 'continue'-command.
 
END GO
</lang>
Example output:
<pre>
@ exec uinput
MACRO: User
LINK: Loading
[LNKXCT USER execution]
Please type a string, 80 chars max.: This is a test.
Please type the decimal number 75000: 74998
Number is not 75000! Please type the decimal number 75000: 74999
Number is not 75000! Please type the decimal number 75000: 75000
This is a test.
75000
@ _
</pre>
 
=={{header|Maple}}==
Anonymous user