Question: All programming exercises in this homework need to be done in machine language, not assembly language. Follow the examples in the book and add pseudocode

All programming exercises in this homework need to be done in machine language,
not assembly language. Follow the examples in the book and add pseudocode to the
right of each instruction.
All of your programs should end with a Halt instruction:
1111000000100101 TRAP x25
1. Write a short LC-3 program that compares the two numbers in R1 and R2 and puts
the value 0 in R0 if R1= R2,1 in R0 if R1> R2 and -1 in R0 if R1< R2.
2. Section 6.1.4 of the text includes an example of character counting. Why is it
necessary to initialize R2 in this example? In other words, in what manner might the
program behave incorrectly if the R20 step were removed from the code?
3. Consider the following machine language program:
0x30000101010010100000
0x30010001001001111111
0x30020001001001111111
0x30030001001001111111
0x30040000100000000010
0x30050001010010100001
0x30060000111111111010
0x30071111000000100101
What are the possible initial values of R1 that cause the final value in R2 to be 3?
4. Shown below are the contents of memory and registers before and after the LC-3
instruction at location 0x3010 is executed.
Your job: Identify the instruction stored in
0x3010(all 16 bits, not just the opcode). Note: There is enough information below to
uniquely specify the instruction at 0x3010.
Before After
R00x32080x3208
R10x2D7C 0x2D7C
R20xE3730xE373
R30x20530x2053
R40x33FF 0x33FF
R50x3F1F 0x3F1F
R60xF4A20xF4A2
R70x52200x5220
Before After
...
0x34000x30010x3001
0x34010x7A000x7A00
0x34020x7A2B 0x7A2B
0x34030xA7000xA700
0x34040xF0110xF011
0x34050x20030x2003
0x34060x31BA 0xE373
0x34070xC1000xC100
0x34080xEFEF 0xEFEF
...
5. Using iteration write a program that displays the first character of your name 100
times on the screen.
Here's the instruction to write a character to the monitor. The TRAP instruction to
write a character to the monitor assumes the character is in bits [7:0] of R0.
1111000000100001 TRAP x21
6. Write a program that determines if the number stored in R4 is odd. If the value of
R4 is odd, the program puts a 1 in R0. Otherwise it puts a 0 in R0.
7. Write a program that determines if the number stored in R4 is even. If the value of
R4 is even, the program puts a 1 in R0. Otherwise it puts a 0 in R0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!