I need to write this in LC-3 assembly language:

We have just read a single numeric digit from the keyboard using the GETC command. Convert this value to binary and place it into R4.

1

There are 1 best solutions below

0
On

Here's an example, adapted from a lab manual written by George M. Georgiou and Brian Strader.

3.2.3 How to read an input value

The assembly command GETC, which is another name for TRAP x20, reads a single character from the keyboard and places its ASCII value in register R0. The 8 most significant bits of R0 are cleared. There is no echo of the read character. For example, one may use the following code to read a single numerical character, 0 through 9, and place its value in register R3:

GETC               ; Place ASCII value of input character into R0
ADD R3, R0, x0     ; Copy R0 into R3
ADD R3, R3, #−16   ; Subtract 48, the ASCII value of 0
ADD R3, R3, #−16
ADD R3, R3, #−16   ; R3 now contains the actual value

Notice that it was necessary to use three instructions to subtract 48, since the maximum possible value of the immediate operand of ADD is 5 bits, in two’s complement format. Thus, -16 is the most we can subtract with the immediate version of the ADD instruction. As an example, if the pressed key was "5", its ASCII value 53 will be placed in R0. Subtracting 48 from 53, the value 5 results, as expected, and is placed in register R3.

Original Source.

You'll need to adapt this to put the result in R4.