Skip to content

Command-Line issues with readchar syscall #135

@jplanck

Description

@jplanck

There is an issue with readchar syscall. The readcall requires a newline to accept the character, and doesn't read the newline char itself. Perhaps the terminal mode line buffering is misconfigured for readchar.

The following code always causes a runtime exception "Error in /home/jplanck/./riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)"

# read chars in a loop, echoing the integer value of each char read 
# stores the chars as as a string and print the string.
.text
	la	t0, str
	li	t1, '\n'

loop:
	li 	a7, 12
	ecall
	li 	a7, 1
	ecall
	sb 	a0, 0(t0)
	addi	t0, t0, 1
	bne	a0, t1, loop
	sb	x0, 0(t0)
	
	li 	a7, 4
	la	a0, str
	ecall
	li 	a7, 10
	ecall
.data
str: .space 20

Here is the runtime response when i type "1234".
java -jar ~/opt/riscv/rars/rars1_5.jar riscv1.asm nc
1234
49
Error in /home/jplanck/riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)

Simulation terminated due to errors.

Here is the output when I type a newline after each char.
java -jar ~/opt/riscv/rars/rars1_5.jar riscv1.asm nc
1
492
503
514
52
Error in /home/jplanck/riscv1.asm line 6: Runtime exception at 0x00400010: invalid char input (syscall 12)

Simulation terminated due to errors.

system info,
Linux version 5.11.0-38-generic (buildd@lgw01-amd64-041) (gcc (Ubuntu 9.3.0-17ubuntu120.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #4220.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions