Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In LC-3: Exercise 02 Write the inverse of a binary printing subroutine. That is, write a binary reading subroutine: First, prompt the user to enter

In LC-3:

Exercise 02 Write the inverse of a binary printing subroutine. That is, write a binary reading subroutine: First, prompt the user to enter a 16-bit 2s complement binary number The user will enter 'b' followed by exactly sixteen 1s and 0s: e.g. b0001001000110100 (no spaces on input) Your subroutine should do the following: 1. The user enters a binary number as a sequence of 17 ascii characters: b0010010001101000 2. The result of (1) is transformed into a single 16-bit value, which is stored in R2. 3. Call the subroutine from Exercise 01 to print the value of R2 back out to the console to check your work. Algorithm: total <-- 0 counter <-- 16 R0 <-- get input from user (the initial b) and do nothing with it do { ; that's your job :) ; HINT: the 4-bit binary number b1011 is (b101 * #2 + 1) } while ( counter > 0 ); Exercise 03 Enhance exercise 2 so that it now performs some input validation. Thus, If the first character entered is not 'b', the program should output an error message and go back to the beginning After that, if a SPACE is ever entered, the program should only echo it and continue (i.e. spaces are ignored in the conversion algorithm). If any character other than '1', '0' or SPACE is entered after the initial b, the program should output an error message and ask for a valid character - i.e. it should keep everything received so far, and keep looping until it gets a valid '0', '1' or space.

Also this is what exercise one looks like

.orig x3000

LEA R0, MSG PUTS

LD R4, OUTPUT_SUBROUTINE JSRR R4

PUTS

HALT

OUTPUT_SUBROUTINE .FILL x3200 MSG .STRINGZ "Output subroutine " MSG_END .stringz "OUTput subroutine "

.orig x3200 ;store your register to memory ST R0, BACKUP_R0_x3200 ST R1, BACKUP_R1_x3200 ST R2, BACKUP_R2_x3200 ST R3, BACKUP_R3_x3200 ST R4, BACKUP_R4_x3200 ST R5, BACKUP_R5_x3200 ST R6, BACKUP_R6_x3200 ST R7, BACKUP_R7_x3200

LD R4, ARRAY_PTR LD R5, COUNTER LD R3, NEW_LINE ; I want to print 10 lines LD R6, POSITION ; Where to print 1

LOOP_1 STR R5,R4,#0 ADD R5,R5,R5 ADD R4,R4, #1 ADD R6,R6,#-1 BRp LOOP_1 ;if counter is still positive, loop it END_INPUT_LOOP

;how to get the seventh value

LD R4, ARRAY_PTR LD R6, COUNTER

LOOP_2 LDR R0,R4, #0 ADD R0,R0, R3 Trap x21 ADD R4, R4, #1 ADD R6, R6, #-1 BRp LOOP_2

OUTER_LOOP LD R5, COUNTER LD R2, SPACE_COUNTER

INNER_LOOP ;task of inner loop is to print one line ADD R0, R5, R6 ; i changed r2 to r6 because r6 was ;taken BRnp PRINT_ZERO PRINT_ONE LD R0, ONE OUT BR END_PRINTING_ZERO_ONE PRINT_ZERO LD R0, ZERO OUT END_PRINTING_ZERO_ONE

ADD R5, R5, #-1 BRp INNER_LOOP

ADD R2, R2, #-1 BRp CONTINUE_INNER_LOOP PRINT_SPACE LD R0, SPACE OUT LD R2, SPACE_COUNTER CONTINUE_INNER_LOOP ADD R5,R5, #-1 BRp INNER_LOOP END_INNER_LOOP LD R0, NEW_LINE OUT ADD R6,R6, #-1 ADD R3,R3, #-1 BRp OUTER_LOOP

;Load regsiter from memory LD R0, BACKUP_R0_x3200 LD R1, BACKUP_R1_x3200 LD R2, BACKUP_R2_x3200 LD R3, BACKUP_R3_x3200 LD R4, BACKUP_R4_x3200 LD R5, BACKUP_R5_x3200 LD R6, BACKUP_R6_x3200 LD R7, BACKUP_R7_x3200 RET

ARRAY_PTR .FILL x4000 ZERO .FILL #48 ONE .FILL #49 COUNTER .FILL #16 POSITION .FILL #-1 NEW_LINE .FILL #10 SPACE .FILL x000A SPACE_COUNTER .FILL #4

BACKUP_R0_x3200 .BLKW #1 BACKUP_R1_x3200 .BLKW #1 BACKUP_R2_x3200 .BLKW #1 BACKUP_R3_x3200 .BLKW #1 BACKUP_R4_x3200 .BLKW #1 BACKUP_R5_x3200 .BLKW #1 BACKUP_R6_x3200 .BLKW #1 BACKUP_R7_x3200 .BLKW #1

.orig x4000

ARRAY_1 .BLKW #10

.end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899