Question

I am writing a code for the LC3 Simulator. This is in assembly, I need assistance...

I am writing a code for the LC3 Simulator. This is in assembly, I need assistance with the numbers 5-8. Thank you.

ALU OPERATIONS

1. Compute the sum X +Y and place it at location x3102.

2. Compute X AND Y and place it at location x3103.

3. Compute X OR Y and place it at location x3104.

4. Compute NOT(X) and place it at location x3105.

5. Compute NOT(Y) and place it at location x3106.

6. Compute X +3 and place it at location x3107.

7. Compute Y −3 and place it at location x3108.

8. If the X is even, place 0 at location x3109. If the number is odd, place 1 at the same location

MY CODE SO FAR (COMPLETED 1-4):

   .ORIG x3000
   LEA R2, xFF   ;R2 Loaded with the begenning address of data
   LDR R1, R1, x0   ;X, located at x3100, and loaded in R1
   LDR R3, R2, x1   ;Y, located at x3101, and loaded in R2

   ;X + Y
   AND R4, R4, x0   ;Clearing R4
   ADD R4, R1, R3   ;Addition of X and Y
   STR R4, R2, x2   ;Storing in x3102

   ;And Gate of X and Y
   AND R4, R4, x0   ;Clearing R4
   AND R4, R1, R3   ;AND gate
   STR R4, R2, x3   ;Storing in x3103

   ;OR of X and Y
   AND R4, R4, x0
   NOT R1, R1
   NOT R3, R3
   AND R4, R1, R3
   NOT R4, R4
   STR R4, R2, x4

   ;RESTORE
   NOT R1, R1
   NOT R3, R3
  
   ;NOT GATE OF X
   AND R4, R4, x0
   AND R4, R1, R1
   NOT R4, R4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM:

.ORIG x3000
LEA R2,xFF ; R2 Loaded with the beginning address of data
LDR R1,R2,x0 ; X, located at x3100, and loaded in R1
LDR R3,R2,x1 ; Y, located at x3101, and loaded in R3

; X+Y
AND R4,R4,x0 ; Clearing R4
ADD R4,R1,R3 ; Addition of X and Y
STR R4,R2,x2 ; Storing in x3102

; X AND Y
AND R4,R4,x0 ; Clearing R4
AND R4,R1,R3 ; AND of X and Y
STR R4,R2,x3 ; Storing in x3103

; X OR Y
AND R4,R4,x0 ; Clearing R4
NOT R1,R1 ; Complement R1
NOT R3,R3 ; Complement R3
AND R4,R1,R3 ; AND of X and Y
NOT R4,R4 ; NOT of R4
STR R4,R2,x4 ; Storing in x3104
; Restore X and Y
NOT R1,R1 ; Complement R1
NOT R3,R3 ; Complement R3

; NOT of X
AND R4,R4,x0 ; Clearing R4
AND R4,R1,R1 ; Load R4 with X
NOT R4,R4 ; NOT of X
STR R4,R2,x5 ; Storing in x3105

; NOT of Y
AND R4,R4,x0 ; Clearing R4
AND R4,R3,R3 ; Load R4 with Y
NOT R4,R4 ; NOT of Y
STR R4,R2,x6 ; Storing in x3106

; X+3
AND R4,R4,x0 ; Clearing R4
ADD R4,R1,x3 ; ADD X with 3
STR R4,R2,x7 ; Storing in x3107

; Y-3
AND R4,R4,x0 ; Clearing R4
ADD R4,R4,x3 ; Loading R4 with value 3
NOT R4,R4 ; Complement R4
ADD R4,R4,x1 ; 2's complement of 3
ADD R4,R3,R4 ; ADD Y and -3 to get Y-3
STR R4,R2,x8 ; Storing in x3108

; IS X EVEN OR ODD
AND R4,R4,x0 ; Clearing R4
AND R0,R1,x1 ; AND X with 1 to check the LAB bit
BRZ X_EVEN ; If value is zero, X is enen
ADD R4,R4,x1 ; Else X is ODD, Load R4,1
X_EVEN STR R4,R2,x9 ; Storing in x3109
.END

Please refer to the following screenshot of the program for indentation of code:

OUTPUT:

Data Memory before execution of program:

Data Memory after execution of program:

Add a comment
Know the answer?
Add Answer to:
I am writing a code for the LC3 Simulator. This is in assembly, I need assistance...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin ...

    LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin reserved section: do not change ANYTHING in reserved section! .ORIG x3000 BR Main ; Parameter and result Param .FILL x0004 Result .BLKW 1 ; Constants Stack .FILL x4000 One .FILL #1 MinusOne .FILL #-1 ; End reserved section: do not change ANYTHING in reserved section! ;------------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; int Factorial(int N) ; Returns N! (must be a recursive function) ; Factorial ;__________________...

  • Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR...

    Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR REPEAT LDR R3, R1, #0 BRz FINISH   ;Branch to FINISH if the value of R3 is zero ADD R3, R3, R4 BRnp PASS   ;Branch to PASS if the value of R3 is positive or negative ADD R2, R2, #1 PASS ADD R1, R1, #1 BR REPEAT   ;Branch always to REPEAT FINISH ST R2, COUNT HALT CHAR .FILL xFF91 COUNT .FILL x0000 STRZ .STRINGZ "Hello...

  • LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to...

    LC-3 Programming Help!! The Stack Protocol The following outline is the protocol for passing arguments to a function and returning values. Everything is stored on the runtime stack so that space is used only when the function is executing. As a result the actual address of arguments and locals may change from call to call. However, the layout of the stack frame (activation record) is constant. Thus, the offests from the frame pointer (FP) to the parameters/locals are constant. All...

  • 1.) a.) Using the simplified instruction set shown for part b, write code for the following....

    1.) a.) Using the simplified instruction set shown for part b, write code for the following. Suppose memory locations 1400 to 1449 contain 16-bit words. Each word represents 2 ASCII characters. Write code to read in and write out these 100 characters. Left-side character from location 1400 should be first, right-side character from location 1400 should be second, and remaining characters follow in numeric order. Assume you have access to 4 registers: R1, R2, R3, R4. Each register holds one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT