Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LC-3 Language Help!!! ; test harness .orig x3000 halt ;----------------------------------------------------------------------------------------------- ; test harness local data: ;=============================================================================================== ; subroutines: ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_PRINT_OPCODE_TABLE ; Parameters: None

LC-3 Language Help!!!

image text in transcribed

image text in transcribed

; test harness .orig x3000 halt ;----------------------------------------------------------------------------------------------- ; test harness local data:

;===============================================================================================

; subroutines: ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_PRINT_OPCODE_TABLE ; Parameters: None ; Postcondition: The subroutine has printed out a list of every LC3 instruction ; and corresponding opcode in the following format: ; ADD = 0001 ; AND = 0101 ; BR = 0000 ; ; Return Value: None ;----------------------------------------------------------------------------------------------- .orig x3200 ret ;----------------------------------------------------------------------------------------------- ; SUB_PRINT_OPCODE_TABLE local data opcodes_po_ptr .fill x4000 ; local pointer to remote table of opcodes instructions_po_ptr .fill x4100 ; local pointer to remote table of instructions

;===============================================================================================

;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_PRINT_OPCODE ; Parameters: R2 containing a 4-bit op-code in the 4 LSBs of the register ; Postcondition: The subroutine has printed out just the 4 bits as 4 ascii 1s and 0s ; The output is NOT newline terminated. ; Return Value: None ;----------------------------------------------------------------------------------------------- .orig x3400 ret ;----------------------------------------------------------------------------------------------- ; SUB_PRINT_OPCODE local data

;===============================================================================================

;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_FIND_OPCODE ; Parameters: None ; Postcondition: The subroutine has invoked the SUB_GET_STRING subroutine and stored a string ; as local data; it has searched the AL instruction list for that string, and reported ; either the instruction/opcode pair, OR "Invalid instruction" ; Return Value: None ;----------------------------------------------------------------------------------------------- .orig x3600 ret ;----------------------------------------------------------------------------------------------- ; SUB_FIND_OPCODE local data opcodes_fo_ptr .fill x4000 instructions_fo_ptr .fill x4100

;===============================================================================================

;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_GET_STRING ; Parameters: R2 - the address to which the null-terminated string will be stored. ; Postcondition: The subroutine has prompted the user to enter a short string, terminated ; by [ENTER]. That string has been stored as a null-terminated character array ; at the address in R2 ; Return Value: None (the address in R2 does not need to be preserved) ;----------------------------------------------------------------------------------------------- .orig x3800 ret ;----------------------------------------------------------------------------------------------- ; SUB_GET_STRING local data

;===============================================================================================

;----------------------------------------------------------------------------------------------- ; REMOTE DATA .ORIG x4000 ; list opcodes as numbers from #0 through #15, e.g. .fill #12 or .fill xC ; opcodes

.ORIG x4100 ; list AL instructions as null-terminated character strings, e.g. .stringz "JMP" ; - be sure to follow same order in opcode & instruction arrays! ; instructions

;===============================================================================================

Exercise 1 Write the following subroutine: Subroutine: SUB_PRINT_OPCODE_TABLE ; Parameters: None ;Postcondition: The subroutine has printed out a list of every LC3 instruction and corresponding Opcode in the following format: ADD = 0001 AND = 0101 BR = 0000 Return value: None Specifications: The data for the subroutine consists of two remote "parallel" arrays: An array of numbers (not strings), each one representing an LC3 opcode (i.e. #1, #5, etc.) An array of strings, each one representing the corresponding LC3 Assembly Language (AL) instruction, in the same order as the opcodes. (i.e. "ADD", "AND", etc.) o When invoked, the subroutine simply prints the tables as described. Hints: The Op-code table from the text is provided at the end of this document. The two arrays will be stored remotely, with the remote addresses provided as local data to the subroutine (this is so that a different subroutine can also access the same arrays) Store the array of opcodes as a list of .FILL pseudo-ops Store the array of AL instructions as a list of STRINGZ pseudo ops Terminate this array of strings with a .FILL #-1 To iterate through the two arrays in parallel, keep a pointer to each array Iterate through the opcode list one memory location at a time You could print out each AL instruction using PUTS (Trap x22) - but we only have a pointer to the start of the entire array of strings, i.e. the address of the first instruction!! We don't know the start address of the rest of them! So you are going to use the starting address of the whole array, and iterate through it character by character, printing each with OUT (Trap x21), stopping at the #0 (i.e. essentially make your own PUTS subroutine!) At that point, you will print the "=", print the opcode and a newline, and then increment the two array pointers and start over. Print the opcode with the helper subroutine described below, passing it in as a number in R2 Quit when the instruction array pointer points to the value xFFFF = #-1 (use BRn) MAKE SURE YOU DO NOT PRINT THE TERMINATING NULL!! As always you must keep the simpl text window open to report runtime errors. You will need a helper subroutine to print the op-codes. Create a version of your Assignment 3 as a subroutine that takes a register parameter. Skip the 12 MSBS, and print out just the 4 LSBS, as ascii 1s and Os (no terminating newline - leave that to the parent subroutine). So when passed e.g. the value #12 (XO0OC) in R2, the sub will print out "1100" ; Subroutine: SUB_PRINT_OPCODE Parameters: R2 containing a 4-bit Op-code in the 4 LSBs of the register ; Postcondition: The subroutine has printed out just the 4 bits as 4 ascii 1s and Os The output is NOT newline terminated. Return value: None (but the input register R2 is unchanged) : Test Harness: Write a test harness that calls the SUB_PRINT_OPCODE_TABLE (the SUB_PRINT_OPCODE will be called from inside that subroutine - this is the first time you will be using a nested subroutine call! Be very careful about backing up & restoring ONLY the necessary registers). Fair Warning: If you use STRINGZ to simply store "ADD = 0001" (or any similar cheating hack-job) etc and print it out that way, you will not only get no credit for the lab, you will also receive a heavy sigh and will be walked away from in tired dismissal by the TA. Exercise 2 Build a second pair of subroutines (same master/helper structure) that allow a user to repeatedly type in instruction names (example: "ADD", "ISR", "BR") and be told whether the instruction is valid (whether the instruction exists). ; Subroutine: SUB_FIND_OPCODE ; Parameters: None ;Postcondition: The subroutine has invoked the SUB_GET_STRING subroutine and stored a string as local data; it has searched the AL instruction list for that string, and reported either the instruction/opcode pair, OR "Invalid instruction" Return Value: None : ; ; Subroutine: SUB_GET_STRING ; Parameters: R2 - the address to which the null-terminated string will be stored. Postcondition: The subroutine has prompted the user to enter a short string, terminated by [ENTER]. That string has been stored as a null-terminated character array at the address in R2 Return value: None (the address in R2 does not need to be preserved) ; Specifications: The FIND subroutine invokes the GET_STRING sub, which prompts the user to type an [ENTER]-terminated string, which is stored as local data in the FIND sub (make sure to allocate enough memory locally for this string) The input string is compared with the array of LC3 instructions. As in the previous subroutine, the two arrays are accessed via locally-stored addresses. If the input string matches one of the instructions, then that line from the opcode table is printed out. Otherwise "Invalid instruction" is printed. Examples: The user types "SRR[ENTER]" The subroutine prints "SRR = 0100" The user types "AMD[ENTER]" The subroutine prints "Invalid instruction" Test Harness: Just add a call to SUB_FIND_OPCODE to your harness for exercise 1

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

Big Data And Hadoop Fundamentals Tools And Techniques For Data Driven Success

Authors: Mayank Bhushan

2nd Edition

9355516665, 978-9355516664

More Books

Students also viewed these Databases questions

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago