LC-3 Assembly Help

ScottALot

Active Member
Hey Ya'll

So we're working with LC-3 assembly in my intro class, and we're working on some code that we have to modify to fulfill these requirements.

1FuYv7C.png


The code in question is

Code:
; inputs a 16-bit binary value from the keyboard (one bit at a time)
; puts the resulting value into register R3
; assume the user only types 0 or 1 (no error handling!)

	.ORIG x3000
START
; initialize values

INIT 	LD 	R4, 	ASCIIDIFF 	; to convert ASCII code to numberic value
	AND	R3,	R3, 	R0	; initialize number value to 0
	LD	R2,	NBITS		; # bits to input (loop control)

; get a key from the keyboard

WAITKEY	LDI	R3,	KBSR
	BRzp	WAITKEY
GOTKEY	LDI	R2,	KBDR

; convert ASCII code to numeric value

CONVERT	ADD	R0,	R0,	R4

; shift register one position to the left (same as multiply by 2)
; then add in new bit value at the least-significant position

APPEND	ADD	R3,	R3,	R3
	ADD	R3,	R3,	R0

; decrement loop variable and iterate if non-zero

ITERATE	ADD	R2,	R2,	#-1
	BRnp	WAITKEY

; if the program gets here, then it's done and should stop

DONE	HALT

; --- PROGRAM DATA ---

ASCIIDIFF	.FILL	XFFD0	; difference between ASCII and numeric values
NBITS		.FILL	#16	; # of bits to input
KBSR		.FILL	xFE00	; keyboard status register address
KBDR		.FILL	xFE02	; keyboard data register address

	.END

Any of you guys good with this?
 

ScottALot

Active Member
Okay so I modified the code and I think it works as desired... but the program they have us using to test code is SO cumbersome. If you see any bugs in here, please don't hesitate to question/correct me. I have an hour to make corrections :p

Code:
; inputs a 16-bit binary value from the keyboard (one bit at a time)
; puts the resulting value into register R3
; assume the user only types 0 or 1 (no error handling!)

; R0 - Holds ASCII-converted values
; R1 - Holds KBSR
; R2 - Unused (held NBITs in unmodified code)
; R3 - Holds resulting value
; R4 - Holds ASCII offset for converting ASCII digits to HEX
; R5 - Holds temp value for Test1

	.ORIG x3000
START
; initialize values

INIT 	LD 	R4, 	ASCIIDIFF 	; to convert ASCII code to numberic value
	AND	R3,	R3, 	R0	; initialize number value to 0
	
; shift register one position to the left (same as multiply by 2)
; then add in new bit value at the least-significant position

APPEND	ADD	R3,	R3,	R3
	ADD	R3,	R3,	R0

; get a key from the keyboard

WAITKEY	LDI	R1,	KBSR
	BRzp	WAITKEY
GOTKEY	LDI	R0,	KBDR

; convert ASCII code to numeric value

CONVERT	ADD	R0,	R0,	R4

; if converted value equals 0, append

TEST0	BRz	APPEND

; if converted value equals 1, append

TEST1	AND	R5,	R5,	#0	; reset R5 to 0
	ADD	R5,	R0,	#-1	; store R0+(-1) in R5
	BRz	APPEND			; if R5=0 (R0=1), Append

; if the program gets here, then it's done and should stop

DONE	HALT

; --- PROGRAM DATA ---

ASCIIDIFF	.FILL	XFFD0	; difference between ASCII and numeric values
KBSR		.FILL	xFE00	; keyboard status register address
KBDR		.FILL	xFE02	; keyboard data register address

	.END
 
Top